Submission #1084893

#TimeUsernameProblemLanguageResultExecution timeMemory
1084893SunbaeSynchronization (JOI13_synchronization)C++17
0 / 100
151 ms23864 KiB
#include <bits/stdc++.h> #define z exit(0) #define mp make_pair #define F first #define S second using namespace std; using pii = pair<int,int>; const int N = 1e5 + 5; pii A[N], e[N]; vector<int> g[N]; int tin[N], tout[N], timer = 1, up[N][18], LOG, bit[N<<1]; bool active[N]; void upd(int i, int val){ for(; i<timer; i+=i&-i) bit[i] += val;} int qry(int i){ int res = 0; for(; i; i-=i&-i) res += bit[i]; return res;} void dfs(int u, int p){ up[u][0] = p; tin[u] = timer++; for(int j = 1; j<LOG; ++j) up[u][j] = up[up[u][j-1]][j-1]; for(int v: g[u]) if(v != p) dfs(v, u); tout[u] = timer++; } int find_root(int u){ int qry_u = qry(tin[u]), v = u; for(int j = LOG-1; j>=0; --j) if(qry(tin[up[u][j]]) == qry_u) v = up[u][j]; return v; } signed main(){ int n, m, q; scanf("%d %d %d", &n, &m, &q); LOG = 32 - __builtin_clz(n); for(int i = 0, u, v; i<n-1; ++i){ scanf("%d %d", &u, &v); --u; --v; e[i] = mp(u, v); g[u].emplace_back(v); g[v].emplace_back(u); } fill(A, A+n, mp(1, 0)); dfs(0, 0); for(int i = 0; i<n-1; ++i){ int u = e[i].F, v = e[i].S; if(tin[u] > tin[v]) swap(u, v); upd(tin[v], +1); upd(tout[v], -1); } for(int i = 0, j; i<m; ++i){ scanf("%d", &j); --j; int u = e[j].F, v = e[j].S; if(tin[u] > tin[v]) swap(u, v); if(active[j]){ int root = find_root(u); A[v] = mp(A[root].F, A[root].F); upd(tin[v], +1); upd(tout[v], -1); }else{ int root = find_root(u); A[root].F += A[v].F - A[v].S; upd(tin[v], -1); upd(tout[v], +1); } active[j] ^= 1; } while(q--){ int u; scanf("%d", &u); --u; printf("%d\n", A[find_root(u)].F); } }

Compilation message (stderr)

synchronization.cpp: In function 'int main()':
synchronization.cpp:28:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |  int n, m, q; scanf("%d %d %d", &n, &m, &q); LOG = 32 - __builtin_clz(n);
      |               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |   scanf("%d %d", &u, &v); --u; --v;
      |   ~~~~~^~~~~~~~~~~~~~~~~
synchronization.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |   scanf("%d", &j); --j;
      |   ~~~~~^~~~~~~~~~
synchronization.cpp:58:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |   int u; scanf("%d", &u); --u; printf("%d\n", A[find_root(u)].F);
      |          ~~~~~^~~~~~~~~~
#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...