Submission #786293

#TimeUsernameProblemLanguageResultExecution timeMemory
786293chanhchuong123Railway (BOI17_railway)C++14
100 / 100
175 ms46100 KiB
#include <bits/stdc++.h> using namespace std; #define task "" #define fi first #define se second #define all(x) x.begin(), x.end() #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORD(i, a, b) for (int i = (b), _a = (a); i >= _a; --i) template <typename T1, typename T2> bool minimize(T1 &a, T2 b) { if (a > b) {a = b; return true;} return false; } template <typename T1, typename T2> bool maximize(T1 &a, T2 b) { if (a < b) {a = b; return true;} return false; } const int dx[] = {-1, 0, 0, +1}; const int dy[] = {0, -1, +1, 0}; const int MAX = 100100; int n, k, m; int ID[MAX]; vector<int> res; set<int> add[MAX]; vector<int> del[MAX]; int h[MAX], anc[17][MAX]; vector<pair<int, int>> adj[MAX]; void dfs(int u, int p) { for (pair<int, int> &x: adj[u]) if (x.fi != p) { int v = x.fi; ID[v] = x.se; anc[0][v] = u; h[v] = h[u] + 1; for (int j = 1; j <= 16; ++j) { anc[j][v] = anc[j - 1][anc[j - 1][v]]; } dfs(v, u); } } int lca(int u, int v) { if (h[u] < h[v]) swap(u, v); int k = h[u] - h[v]; for (int j = 0; (1 << j) <= k; ++j) { if (k >> j & 1) u = anc[j][u]; } if (u == v) return u; for (int j = 16; j >= 0; --j) { if (anc[j][u] != anc[j][v]) { u = anc[j][u]; v = anc[j][v]; } } return anc[0][u]; } void reDfs(int u, int p) { for (pair<int, int> &x: adj[u]) if (x.fi != p) { int v = x.fi; reDfs(v, u); if (add[u].size() < add[v].size()) add[u].swap(add[v]); for (int x: add[v]) add[u].insert(x); } for (int &x: del[u]) add[u].erase(x); if (add[u].size() >= k && u != 1) { res.push_back(ID[u]); } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } cin >> n >> m >> k; for (int i = 1; i < n; ++i) { int u, v; cin >> u >> v; adj[u].push_back({v, i}); adj[v].push_back({u, i}); } dfs(1, -1); for (int i = 1; i <= m; ++i) { int s, c, u; cin >> s >> c; --s; add[c].insert(i); while (s--) { cin >> u; c = lca(c, u); add[u].insert(i); } del[c].push_back(i); } reDfs(1, -1); sort(all(res)); cout << res.size() << '\n'; for (int &x: res) cout << x << ' '; return 0; }

Compilation message (stderr)

railway.cpp: In function 'void reDfs(int, int)':
railway.cpp:64:23: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   64 |     if (add[u].size() >= k && u != 1) {
      |         ~~~~~~~~~~~~~~^~~~
railway.cpp: In function 'int main()':
railway.cpp:73:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
railway.cpp:74:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...