# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
701483 | 2023-02-21T10:40:33 Z | sugartheanh | Synchronization (JOI13_synchronization) | C++14 | 5 ms | 5076 KB |
#include <bits/stdc++.h> using namespace std; #define dbg(x) cerr << #x << ": " << x << endl; #define ii pair<int,int> #define fi first #define se second const int MOD = 1e9 + 7; const int N = 2e5 + 5; int n,m,q,first[N],last[N],d[N],root; vector<ii>p[N]; bool on[N]; void dfs(int x,int u,int R) { for(auto v : p[u]) { if(v.fi == x) continue; if(first[v.se] < R) { dfs(u,v.fi,min(R,last[v.se])); d[u] += d[v.fi]; } } } int main() { freopen("NEW.INP","r",stdin); freopen("NEW.OUT","w",stdout); ios_base::sync_with_stdio(false); cin.tie(nullptr); cin>>n>>m>>q; for(int i = 1;i < n;i++) { int u,v; cin>>u>>v; p[u].push_back(ii(v,i)); p[v].push_back(ii(u,i)); } for(int i = 1;i <= n;i++) first[i] = 1e9; for(int i = 1;i <= m;i++) { int x; cin>>x; if(!on[x]) first[x] = min(first[x], i); else last[x] = max(last[x], i); on[x] ^= 1; } for(int i = 1;i < n;i++) { if(first[i] < 1e9 && last[i] == 0) last[i] = 1e9; // cout<<first[i]<<' '<<last[i]<<'\n'; } // cout<<'\n'; while(q--) { cin>>root; for(int i = 1;i <= n;i++) d[i] = 1; dfs(0,root,1e9); // for(int i = 1;i <= n;i++) // cout<<i<<' '<<d[i]<<'\n'; // cout<<'\n'; cout<<d[root]<<'\n'; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 5076 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 5076 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 5076 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 5076 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 5076 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |