Submission #815049

#TimeUsernameProblemLanguageResultExecution timeMemory
815049jajcoJail (JOI22_jail)C++17
61 / 100
5101 ms24244 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){ // wczytanie grafu 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,pn(n+1, -1),kn(n+1, -1); REP(i, m){ // wczytanie ziomow scanf("%d%d", &pocz[i], &kon[i]); pn[pocz[i]]=i,kn[kon[i]]=i; } std::vector <vi> dag(m, vi()); vi ile(m); REP(k, m){ // generacja daga static std::function <bool(int, int, int, int)> DFS=[&](int i, int ojc, int d, int id){ bool r=i==d; if (!r) for (int j : pol[i]) if (j!=ojc) if (r|=DFS(j, i, d, id)) break; if (r){ if (pn[i]>=0&&pn[i]!=id) // musimy byc po nim dag[pn[i]].emplace_back(id),++ile[id]; if (kn[i]>=0&&kn[i]!=id) // musimy byc przed nim dag[id].emplace_back(kn[i]),++ile[kn[i]]; } return r; }; DFS(pocz[k], pocz[k], kon[k], k); } bool czy=0; vi zer; REP(i, m) if (!ile[i]) zer.emplace_back(i); int w=0; while (zer.size()){ ++w; int p=zer.back(); zer.pop_back(); for (int i : dag[p]) if (!--ile[i]) zer.emplace_back(i); } czy=w==m; 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...