Submission #1058401

#TimeUsernameProblemLanguageResultExecution timeMemory
1058401fuad27Thousands Islands (IOI22_islands)C++17
10 / 100
21 ms9284 KiB
#include "islands.h" #include <bits/stdc++.h> using namespace std; std::variant<bool, std::vector<int>> find_journey( int N, int M, std::vector<int> U, std::vector<int> V) { vector<vector<pair<int,int>>> g(N); for(int i = 0;i<M;i++) { g[U[i]].push_back({V[i],i}); } bool subt2=1; { vector<vector<int>> a(N, vector<int>(N, -1)); for(int i = 0;i<M;i++) { a[U[i]][V[i]] = i; } for(int i= 0;i<N;i++) { for(int j = 0;j<N;j++) { if(i==j)continue; if(a[i][j]==-1)subt2=false; } } if(M!=N*(N-1))subt2=false; } if(N == 2) { if(g[0].size() < 2)return false; if(g[1].size() == 0)return false; vector<int> v; v.push_back(g[0][0].second); v.push_back(g[1][0].second); v.push_back(g[0][1].second); v.push_back(g[0][0].second); v.push_back(g[1][0].second); v.push_back(g[0][1].second); return v; } else if(subt2) { if(N <= 2) { return false; } vector<vector<int>> a(N, vector<int>(N, -1)); for(int i = 0;i<M;i++) { a[U[i]][V[i]] = i; } vector<int> ans={a[0][1], a[1][2], a[2][1], a[0][1], a[0][2], a[1][2], a[2][1], a[0][2]}; return ans; } else { vector<int> topo; vector<bool> vis(N); int timer = 0; vector<int> tin(N), tout(N); bool check=false; auto dfs = [&](int at, auto &&dfs) -> void { vis[at]=1; tin[at] = ++timer; for(auto [to,w]:g[at]) { if(!vis[to]) dfs(to, dfs); } tout[at] = ++timer; }; auto dfs2 = [&](int at, int par, auto &&dfs2) -> void { vis[at]=1; for(auto [to,w]:g[at]) { if(!vis[to]) dfs2(to, at, dfs2); else if(vis[to]) { if(to!=par and tin[to] <= tin[at] and tout[at] <= tout[to]) check=true; } } }; for(int i= 0;i<N;i++) { if(!vis[i]) dfs(i, dfs); } vis.assign(N, 0); for(int i= 0;i<N;i++) { if(!vis[i]) dfs2(i, -1, dfs2); } return check; } 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...