Submission #1000410

#TimeUsernameProblemLanguageResultExecution timeMemory
1000410onbertJail (JOI22_jail)C++17
72 / 100
2326 ms1048576 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int maxn = 120005, maxN = 480005, lgn = 17, INF = 1e18; int n, m; vector<int> ADJ[maxn], adj[maxn]; pair<int,int> a[maxn]; int sz[maxn], fa[maxn], d[maxn], newid[maxn], lim[maxn], cnter = 0; void dfs1(int u) { sz[u] = 1; int f = -1; for (int v:ADJ[u]) { if (sz[v]) { f = v; continue; } dfs1(v); sz[u] += sz[v]; } if (f!=-1) ADJ[u].erase(find(ADJ[u].begin(), ADJ[u].end(), f)); // cout << u << endl; // for (int v:ADJ[u]) cout << v << " "; cout << endl; for (int j=1;j<ADJ[u].size();j++) if (sz[ADJ[u][j]] > sz[ADJ[u][0]]) swap(ADJ[u][0], ADJ[u][j]); } void dfs2(int u) { cnter++; newid[u] = cnter; for (int v:ADJ[u]) { d[cnter+1] = d[newid[u]] + 1; dfs2(v); fa[newid[v]] = newid[u]; } lim[newid[u]] = cnter; } int S[maxn], T[maxn], vis[maxn]; bool die = false; vector<int> dep[maxn]; void dfs3(int u) { vis[u] = 1; for (int v:dep[u]) { if (!vis[v]) dfs3(v); else if (vis[v]==1) die = true; } vis[u] = 2; } void solve() { cin >> n; for (int i=1;i<=n;i++) sz[i] = 0, adj[i].clear(), ADJ[i].clear(); cnter = 0; for (int i=1;i<=n-1;i++) { int u, v; cin >> u >> v; ADJ[u].push_back(v); ADJ[v].push_back(u); } fa[1] = 0, d[1] = 0; dfs1(1); dfs2(1); for (int i=1;i<=n;i++) S[i] = -1, T[i] = -1; cin >> m; for (int i=1;i<=m;i++) { int s, t; cin >> s >> t; s = newid[s], t = newid[t]; a[i] = {s, t}; S[s] = i; T[t] = i; } for (int i=1;i<=m;i++) dep[i].clear(); for (int i=1;i<=m;i++) { int u = a[i].first, v = a[i].second; vector<int> path; while (u != v) { if (d[u] > d[v]) swap(u, v); path.push_back(v); v = fa[v]; } path.push_back(u); for (int j:path) { if (S[j]!=-1) dep[i].push_back(S[j]); if (T[j]!=-1) dep[T[j]].push_back(i); } } for (int i=1;i<=m;i++) { sort(dep[i].begin(), dep[i].end()); dep[i].erase(unique(dep[i].begin(), dep[i].end()), dep[i].end()); dep[i].erase(find(dep[i].begin(), dep[i].end(), i)); // for (int j:dep[i]) cout << j << " "; cout << endl; } for (int i=1;i<=m;i++) vis[i] = 0; die = false; for (int i=1;i<=m;i++) if (!vis[i]) dfs3(i); if (die) cout << "No\n"; else cout << "Yes\n"; } signed main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) solve(); }

Compilation message (stderr)

jail.cpp: In function 'void dfs1(long long int)':
jail.cpp:24:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for (int j=1;j<ADJ[u].size();j++) if (sz[ADJ[u][j]] > sz[ADJ[u][0]]) swap(ADJ[u][0], ADJ[u][j]);
      |                  ~^~~~~~~~~~~~~~
#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...