Submission #814940

#TimeUsernameProblemLanguageResultExecution timeMemory
814940jajcoJail (JOI22_jail)C++17
21 / 100
5064 ms312 KiB
#include <ios> #include <vector> #include <algorithm> #include <functional> #define REP(i, n) for (int i=0; i<n; ++i) typedef std::vector <int> vi; int main(){ int q; scanf("%d", &q); while (q--){ int n; scanf("%d", &n); std::vector <vi> pol(n+1, vi()); REP(i, n-1){ int p,k; scanf("%d%d", &p, &k); pol[p].emplace_back(k); pol[k].emplace_back(p); } int m; scanf("%d", &m); vi pocz(m),kon(m),perm; REP(i, m){ scanf("%d%d", &pocz[i], &kon[i]); perm.emplace_back(i); } bool czy=0; while (1){ std::vector <bool> zaj(n+1, 0); for (int i : pocz) zaj[i]=1; std::function <bool(int, int, int)> DFS=[&]( int i, int ojc, int d){ if (i==d) return true; bool r=0; for (int j : pol[i]) if (j!=ojc&&!zaj[j]) r|=DFS(j, i, d); return r; }; bool w=1; for (int i : perm){ if (!(w&=DFS(pocz[i], pocz[i], kon[i]))) break; zaj[pocz[i]]=0,zaj[kon[i]]=1; } czy|=w; if (czy||!std::next_permutation(perm.begin(), perm.end())) break; } printf(czy ? "Yes\n" : "No\n"); } }

Compilation message (stderr)

jail.cpp: In function 'int main()':
jail.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
jail.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
jail.cpp:16:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |             scanf("%d%d", &p, &k);
      |             ~~~~~^~~~~~~~~~~~~~~~
jail.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%d", &m);
      |         ~~~~~^~~~~~~~~~
jail.cpp:24:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |             scanf("%d%d", &pocz[i], &kon[i]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...