Submission #223586

#TimeUsernameProblemLanguageResultExecution timeMemory
223586DodgeBallManRailway (BOI17_railway)C++14
100 / 100
154 ms21904 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair<int, int> #define x first #define y second const int N = 1e5+5; int n, m, k; int in[N], out[N], sz[N], pos[N], idx[N]; vector<pii> g[N]; vector<int> node[N]; int szn[N], cnt[N], ans; int rans[N]; void dfs(int u, int p) { static int ptr = 0; in[u] = ++ptr, pos[ptr] = u, sz[u] = 1; if(p) for(auto it = g[u].begin(); it != g[u].end(); ++it) if(it->x == p) { g[u].erase(it); break; } for(auto &v : g[u]) { idx[v.x] = v.y; dfs(v.x, u); sz[u] += sz[v.x]; if(sz[v.x] > sz[g[u][0].x]) swap(v, g[u][0]); } out[u] = ptr; } void add(int x) { cnt[x]++; if(cnt[x] == 1) ans++; if(cnt[x] == szn[x]) ans--; } void del(int x) { cnt[x]--; if(cnt[x] == 0) ans--; if(cnt[x] == szn[x]-1) ans++; } void sack(int u, bool keep) { for(auto v : g[u]) if(v != g[u][0]) sack(v.x, false); if(g[u].size()) sack(g[u][0].x, true); for(int v : node[u]) add(v); for(auto v : g[u]) if(v != g[u][0]) for(int i = in[v.x]; i <= out[v.x]; ++i) for(auto x : node[pos[i]]) add(x); rans[idx[u]] = ans; if(!keep) for(int i = in[u]; i <= out[u]; ++i) for(auto x : node[pos[i]]) del(x); } int main() { scanf("%d %d %d", &n, &m, &k); for(int i = 1, u, v; i < n; ++i) { scanf("%d %d", &u, &v); g[u].emplace_back(v, i), g[v].emplace_back(u, i); } dfs(1, 0); for(int i = 0; i < m; ++i) { int q; scanf("%d", &q); szn[i] = q; while(q--) { int v; scanf("%d", &v); node[v].emplace_back(i); } } sack(1, false); vector<int> A; for(int i = 1; i < n; ++i) if(rans[i] >= k) A.emplace_back(i); printf("%d\n", A.size()); for(int v : A) printf("%d ", v); }

Compilation message (stderr)

railway.cpp: In function 'int main()':
railway.cpp:70:28: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n", A.size());
                    ~~~~~~~~^
railway.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &n, &m, &k);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
railway.cpp:55:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &u, &v);
         ~~~~~^~~~~~~~~~~~~~~~~
railway.cpp:60:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int q; scanf("%d", &q);
                ~~~~~^~~~~~~~~~
railway.cpp:63:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             int v; scanf("%d", &v);
                    ~~~~~^~~~~~~~~~
#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...