Submission #1112907

#TimeUsernameProblemLanguageResultExecution timeMemory
1112907ntdaccodeSynchronization (JOI13_synchronization)C++17
40 / 100
8067 ms64240 KiB
#include<bits/stdc++.h> #define fori(i,a,b) for(int i=a;i<=b;i++) #define int long long #define pb push_back using namespace std; typedef pair<int,int> ii; typedef tuple<int,int,int> tp; const int M=1e6+10; const int N=1e3+10; const int mod=1e9+7; int n,m,q; namespace sub1 { vector<ii> ke[M]; vector<int> Q[M]; bool dd[M]; void dfs(int u,int pre,int p) { //cout << u <<" " << pre << " " << p << "\n"; dd[u] = true; for(ii tmp : ke[u]) { int v = tmp.first; int idx = tmp.second; if(v == p) continue; int nxt = 0,tt = 0; for(int i = 0; i < Q[idx].size(); i++) { tt = 1 - tt; if(tt && Q[idx][i] <= pre) { if(i != Q[idx].size()-1) nxt = Q[idx][i + 1] - 1; else nxt = m; } } //cerr << u << ' ' << v << " " << idx << "\n"; if(nxt) dfs(v,min(pre,nxt),u); } } void solve() { for(int i = 1;i <= n - 1; i++) { int u , v; cin >> u >> v; ke[u].pb({v,i}); ke[v].pb({u,i}); } for(int i = 1;i <= m; i++) { int idx; cin >> idx; Q[idx].pb(i); } for(int i = 1;i <= q; i++) { int root; int res = 0; cin >> root; dfs(root,1e9,0); for(int i = 1;i <= n; i++) res += dd[i]; for(int i = 1;i <= n; i++) dd[i] = 0; cout << res << "\n"; } } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen("1.inp","r")) { freopen("1.inp","r",stdin); freopen("1.out","w",stdout); } #define task "" if(fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } cin >> n >> m >> q; sub1::solve(); }

Compilation message (stderr)

synchronization.cpp: In function 'void sub1::dfs(long long int, long long int, long long int)':
synchronization.cpp:28:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for(int i = 0; i < Q[idx].size(); i++) {
      |                        ~~^~~~~~~~~~~~~~~
synchronization.cpp:31:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |             if(i != Q[idx].size()-1) nxt = Q[idx][i + 1] - 1;
      |                ~~^~~~~~~~~~~~~~~~~~
synchronization.cpp: In function 'int32_t main()':
synchronization.cpp:73:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |     freopen("1.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
synchronization.cpp:74:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |     freopen("1.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
synchronization.cpp:79:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
synchronization.cpp:80:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |     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...