Submission #1326310

#TimeUsernameProblemLanguageResultExecution timeMemory
1326310salmonJail (JOI22_jail)C++20
49 / 100
5102 ms251572 KiB
#include <bits/stdc++.h> using namespace std; int Q; int N; int M; vector<int> adjlst[120100]; int up[120100]; int down[120100]; int done[120100]; bool visited[120100]; bool cover[120100]; vector<int> path[120100]; vector<int> tempv; bool findpath(int i, int p, int w){ tempv.push_back(i); if(i == w) return true; for(int j : adjlst[i]){ if(j == p) continue; if(findpath(j,i,w)) return true; } tempv.pop_back(); return false; } int main(){ scanf(" %d",&Q); while(Q--){ scanf(" %d",&N); for(int i = 1; i <= N; i++) adjlst[i].clear(); for(int i = 0; i < N - 1; i ++){ int u,v; scanf(" %d",&u); scanf(" %d",&v); adjlst[u].push_back(v); adjlst[v].push_back(u); } scanf(" %d",&M); for(int i = 1; i <= M; i++){ int u,v; scanf(" %d",&u); scanf(" %d",&v); tempv.clear(); findpath(u,-1,v); path[i] = tempv; //for(int j : path[i]) printf("%d ",j); //printf("\n"); } for(int i = 1; i <= M; i++) done[i] = false; for(int i = 1; i <= M; i++){ for(int i = 1; i <= N; i++) visited[i] = false; for(int i = 1; i <= N; i++) cover[i] = false; for(int k = 1; k <= M; k++){ if(done[k]) continue; visited[path[k][0]] = true; for(int j : path[k]) if(j != path[k].back()) cover[j] = true; } int it = -1; for(int k = 1; k <= M; k++){ if(done[k]) continue; bool die = false; for(int j = 1; j < path[k].size(); j++) die |= visited[path[k][j]]; die |= cover[path[k].back()]; if(!die){ it = k; break; } } if(it == -1){ printf("No\n"); break; } if(i == M){ printf("Yes\n"); } done[it] = true; } } }

Compilation message (stderr)

jail.cpp: In function 'int main()':
jail.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         scanf(" %d",&Q);
      |         ~~~~~^~~~~~~~~~
jail.cpp:34:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |                 scanf(" %d",&N);
      |                 ~~~~~^~~~~~~~~~
jail.cpp:41:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |                         scanf(" %d",&u);
      |                         ~~~~~^~~~~~~~~~
jail.cpp:42:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |                         scanf(" %d",&v);
      |                         ~~~~~^~~~~~~~~~
jail.cpp:48:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |                 scanf(" %d",&M);
      |                 ~~~~~^~~~~~~~~~
jail.cpp:53:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |                         scanf(" %d",&u);
      |                         ~~~~~^~~~~~~~~~
jail.cpp:54:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |                         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...
#Verdict Execution timeMemoryGrader output
Fetching results...