Submission #875760

#TimeUsernameProblemLanguageResultExecution timeMemory
875760dimashhhJail (JOI22_jail)C++17
72 / 100
4215 ms1048576 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5 + 10, MOD = 998244353; vector<int> g[N], x[N], gt[N]; int timer = 0, tin[N], tout[N], n, m, s[N], t[N], pp[N], val[N], used[N], val1[N]; void dfs(int v, int pr = 1) { tin[v] = ++timer; pp[v] = pr; for (int to : g[v]) { if (to == pr) continue; dfs(to, v); } tout[v] = ++timer; } bool is(int v, int u) { return (tin[v] <= tin[u] && tout[v] >= tout[u]); } vector<int> path(int v,int u){ vector<int> p(1,v); while(!is(v,u)){ v = pp[v]; p.push_back(v); } while(!is(u,v)){ p.push_back(u); u = pp[u]; } return p; } bool res = 1; void dfs1(int v){ used[v] = 1; for(int to:gt[v]){ if(used[to] == 1){ res =0 ; } if(!used[to]){ dfs1(to); } } used[v] = 2; } void test() { res = 1; timer = 0; cin >> n; for (int i = 1; i <= n; i++) g[i].clear(); for (int i = 1; i <= n - 1; i++) { int x, y; cin >> x >> y; g[x].push_back(y); g[y].push_back(x); } dfs(1); cin >> m; for(int i = 1;i <= n;i++){ val1[i] = val[i] = 0; } for(int i = 1;i <= m;i++){ gt[i].clear(); } for (int i = 1; i <= m; ++i) { cin >> s[i] >> t[i]; used[i] = 0; val[s[i]] = i; val1[t[i]] = i; } for(int i = 1;i <= m;i++){ for(int j:path(s[i],t[i])){ int x = val[j]; // cout << j << ' '; if(x && x != i){ gt[i].push_back(x); // cout << i << ' ' << x << '\n'; } x = val1[j]; if(x && x != i){ gt[x].push_back(i); // cout << i << ' ' << x << '\n'; } } cout << '\n'; } for(int i = 1;i <= m;i++){ if(!used[i] && res){ dfs1(i); } } cout << (res ? "Yes\n" : "No\n"); } main() { ios_base::sync_with_stdio(0); cin.tie(0); int T = 1; cin >> T; for (int i = 1; i <= T; i++) { test(); } }

Compilation message (stderr)

jail.cpp:101:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  101 | main()
      | ^~~~
#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...