Submission #44730

#TimeUsernameProblemLanguageResultExecution timeMemory
44730choikiwonSynchronization (JOI13_synchronization)C++17
0 / 100
172 ms75480 KiB
#include<bits/stdc++.h> using namespace std; int N, M, Q; vector<int> adj[200010], U, V; int D[100010]; vector<int> Time[200010]; map<int, int> dp1[200010], dp2[200010], chk; void dfs0(int u, int p) { for(int i = 0; i < adj[u].size(); i++) { int e = adj[u][i]; int v = U[e] + V[e] - u; if(v == p) continue; dfs0(v, u); } chk.clear(); for(int i = 0; i < Time[u].size(); i++) { int t = Time[u][i]; int e = D[t]; int v = U[e] + V[e] - u; if(i) dp1[u][t] += dp1[u][ Time[u][i - 1] ]; if(v != p) { if(chk.find(v) != chk.end()) { dp1[u][t] -= 1 + dp1[v][ chk[v] ]; } chk[v] = t; dp1[u][t] += 1 + dp1[v][t]; } } } void dfs1(int u, int p) { if(p != -1) { for(int i = 0; i < Time[u].size(); i++) { int t = Time[u][i]; int e = D[t]; int v = U[e] + V[e] - u; if(v == p) { dp2[u][t] += dp2[v][t]; dp2[u][t] += dp1[v][t] - dp1[u][t]; } else if(i) dp2[u][t] = dp2[u][ Time[u][i - 1] ]; } } for(int i = 0; i < adj[u].size(); i++) { int e = adj[u][i]; int v = U[e] + V[e] - u; if(v == p) continue; dfs1(v, u); } } int main() { scanf("%d %d %d", &N, &M, &Q); for(int i = 0; i < N - 1; i++) { int u, v; scanf("%d %d", &u, &v); u--; v--; adj[u].push_back(i); adj[v].push_back(i); U.push_back(u); V.push_back(v); } for(int i = 0; i < M; i++) { int e; scanf("%d", &e); e--; D[i] = e; Time[ U[e] ].push_back(i); Time[ V[e] ].push_back(i); } dfs0(0, -1); dfs1(0, -1); for(int i = 0; i < Q; i++) { int u; scanf("%d", &u); u--; if(Time[u].size()) printf("%d\n", 1 + dp1[u][ Time[u].back() ] + dp2[u][ Time[u].back() ]); else printf("1\n"); } }

Compilation message (stderr)

synchronization.cpp: In function 'void dfs0(int, int)':
synchronization.cpp:12:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < adj[u].size(); i++) {
                    ~~^~~~~~~~~~~~~~~
synchronization.cpp:20:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < Time[u].size(); i++) {
                    ~~^~~~~~~~~~~~~~~~
synchronization.cpp: In function 'void dfs1(int, int)':
synchronization.cpp:38:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < Time[u].size(); i++) {
                        ~~^~~~~~~~~~~~~~~~
synchronization.cpp:51:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < adj[u].size(); i++) {
                    ~~^~~~~~~~~~~~~~~
synchronization.cpp: In function 'int main()':
synchronization.cpp:60:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &N, &M, &Q);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:63:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int u, v; scanf("%d %d", &u, &v);
                   ~~~~~^~~~~~~~~~~~~~~~~
synchronization.cpp:73:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int e; scanf("%d", &e);
                ~~~~~^~~~~~~~~~
synchronization.cpp:84:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int u; scanf("%d", &u);
                ~~~~~^~~~~~~~~~
#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...