제출 #1244099

#제출 시각아이디문제언어결과실행 시간메모리
1244099lovrotJail (JOI22_jail)C++20
5 / 100
984 ms1114112 KiB
#define db(...) //fprintf(stderr, __VA_ARGS__) #include <cstdio> #include <algorithm> #include <cstring> #include <vector> #define X first #define Y second #define PB push_back using namespace std; const int LOG = 10; const int N = 1 << LOG; int up[N][LOG], dep[N]; int ma[N], iv[N], mrv; vector<int> g[N], h[N]; void dfs(int u, int p) { iv[u] = mrv++; for(int v : g[u]) { if(v != p) { up[v][0] = u; dep[v] = dep[u] + 1; dfs(v, u); } } ma[u] = mrv; } int lca(int a, int b) { if(dep[a] > dep[b]) swap(a, b); for(int i = LOG - 1; i >= 0; --i) { if(dep[up[b][i]] >= dep[a]) { b = up[b][i]; } } if(a == b) { return a; } for(int i = LOG - 1; i >= 0; --i) { if(up[a][i] != up[b][i]) { a = up[a][i]; b = up[b][i]; } } return up[a][0]; } bool under(int a, int b) { return iv[a] >= iv[b] && ma[a] <= ma[b]; } bool onpath(int a, int b, int c) { int anc = lca(b, c); return under(a, anc) && (under(b, a) || under(c, a)); } int bio[N], s[N], t[N]; vector<int> topo; void dag(int u) { if(bio[u]) { return; } bio[u] = 1; for(int v : h[u]) { dag(v); } topo.PB(u); bio[u] = topo.size(); } void task() { int n, q; scanf("%d", &n); topo.clear(); mrv = 0; up[1][0] = 1; for(int i = 1; i <= n; ++i) { g[i].clear(); } for(int i = 0; i < n - 1; ++i) { int u, v; scanf("%d%d", &u, &v); g[u].PB(v); g[v].PB(u); } dfs(1, 0); for(int i = 1; i < LOG; ++i) for(int j = 1; j <= n; ++j) { up[j][i] = up[up[j][i - 1]][i - 1]; } scanf("%d", &q); for(int i = 0; i < q; ++i) { h[i].clear(); bio[i] = 0; scanf("%d%d", s + i, t + i); for(int j = 0; j < i; ++j) { db("%d %d %d : %d, %d %d %d : %d\n", t[i], s[j], t[j], onpath(t[i], s[j], t[j]), t[j], s[i], t[i], onpath(t[j], s[i], t[i])); bool a = onpath(s[i], s[j], t[j]), b = onpath(t[i], s[j], t[j]); bool c = onpath(s[j], s[i], t[i]), d = onpath(t[j], s[i], t[i]); if(a && c || a && b || c && d) { printf("No\n"); return; } if(b) { h[j].PB(i); } if(d) { h[i].PB(j); } } } for(int i = 0; i < q; ++i) { if(!bio[i]) { dag(i); } } for(int i = 0; i < q; ++i) { for(int j : h[i]) { db("%d -> %d\n", i, j); if(bio[i] < bio[j]) { printf("No\n"); return; } } } printf("Yes\n"); } int main() { int t; scanf("%d", &t); for(; t--; ) task(); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

jail.cpp: In function 'void task()':
jail.cpp:74:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
jail.cpp:83:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |                 scanf("%d%d", &u, &v);
      |                 ~~~~~^~~~~~~~~~~~~~~~
jail.cpp:92:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         scanf("%d", &q);
      |         ~~~~~^~~~~~~~~~
jail.cpp:97:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |                 scanf("%d%d", s + i, t + i);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~
jail.cpp: In function 'int main()':
jail.cpp:131:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  131 |         scanf("%d", &t);
      |         ~~~~~^~~~~~~~~~
#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...