Submission #842676

#TimeUsernameProblemLanguageResultExecution timeMemory
842676SUNWOOOOOOOOJail (JOI22_jail)C++17
0 / 100
1 ms4956 KiB
#include <bits/stdc++.h> using namespace std; using pint = array <int, 2>; const int mxN = 120005; vector <int> adj[mxN], v1, v2; pint st[mxN]; int n, m, s1[mxN], s2[mxN]; int solve() { sort(st + 1, st + m + 1); for (int i = 1; i <= m; i++){ if (st[i][0] < st[i][1]) { v1.push_back(st[i][1]); s1[st[i][0]]++, s1[st[i][1] + 1]--; } else { v2.push_back(st[i][1]); s2[st[i][1]]++, s2[st[i][0] + 1]--; } } for (int i = 0; i < (int) v1.size() - 1; i++) if (v1[i] > v1[i + 1]) return 0; for (int i = 0; i < (int) v2.size() - 1; i++) if (v2[i] > v2[i + 1]) return 0; for (int i = 1; i <= n; i++) { s1[i] += s1[i - 1]; // printf("%d ", s1[i]); } // printf("\n"); for (int i = 1; i <= n; i++) { s2[i] += s2[i - 1]; // printf("%d ", s2[i]); } // printf("\n"); for (int i = 1; i <= n; i++) if (s1[i] && s2[i]) return 0; return 1; } int main() { int q; scanf("%d", &q); while (q--) { scanf("%d", &n); for (int i = 1; i <= n; i++) { // init adj[i].clear(); s1[i] = 0, s2[i] = 0; } v1.clear(); v2.clear(); for (int i = 0, a, b; i < n - 1; i++){ scanf("%d %d", &a, &b); adj[a].push_back(b); adj[b].push_back(a); } scanf("%d", &m); for (int i = 1; i <= m; i++) { scanf("%d %d", &st[i][0], &st[i][1]); } if (solve()) printf("YES\n"); else printf("NO\n"); } return 0; }

Compilation message (stderr)

jail.cpp: In function 'int main()':
jail.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
jail.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
jail.cpp:55:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |             scanf("%d %d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~~
jail.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         scanf("%d", &m);
      |         ~~~~~^~~~~~~~~~
jail.cpp:61:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |             scanf("%d %d", &st[i][0], &st[i][1]);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...