Submission #834928

#TimeUsernameProblemLanguageResultExecution timeMemory
834928pavementThousands Islands (IOI22_islands)C++17
1.75 / 100
27 ms4276 KiB
#include "islands.h" #include <bits/stdc++.h> using namespace std; #define pb push_back int cur_scc; vector<int> tp, scc_num, sz_scc, adj_from_0; vector<bool> vis; vector<vector<int> > adj_t, adj_scc_t; void dfs(int u) { if (vis[u]) { return; } vis[u] = 1; for (auto v : adj_t[u]) { dfs(v); } tp.pb(u); } void collect(int u) { if (vis[u]) { return; } vis[u] = 1; scc_num[u] = cur_scc; for (auto v : adj_t[u]) { collect(v); } } vector<int> dp(int u) { if (scc_num[0] == scc_num[u]) { return adj_from_0; } vector<int> cur; for (auto v : adj_scc_t[u]) { auto tmp = dp(v); for (int i : tmp) { bool in = 0; for (int j : cur) { if (i == j) { in = 1; break; } } if (!in) { cur.pb(i); if ((int)cur.size() > 1) { return cur; } } } } return cur; } variant<bool, vector<int> > find_journey(int N, int M, vector<int> U, vector<int> V) { vis.resize(N); scc_num.resize(N); adj_t.resize(N); adj_scc_t.resize(N); for (int i = 0; i < M; i++) { if (U[i] == 0) { adj_from_0.pb(i); } adj_t[V[i]].pb(U[i]); } for (int i = 0; i < N; i++) { dfs(i); } reverse(tp.begin(), tp.end()); fill(vis.begin(), vis.end(), 0); for (int i : tp) { collect(i); cur_scc++; } sz_scc.resize(cur_scc); for (int i = 0; i < N; i++) { sz_scc[scc_num[i]]++; } for (int i = 0; i < M; i++) { if (scc_num[U[i]] != scc_num[V[i]]) { adj_scc_t[scc_num[V[i]]].pb(scc_num[U[i]]); } } for (int i = 0; i < cur_scc; i++) { auto vec = dp(i); if (sz_scc[i] > 1 && (int)vec.size() > 1) { return true; } } return false; }
#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...