Submission #655345

#TimeUsernameProblemLanguageResultExecution timeMemory
655345LoboThousands Islands (IOI22_islands)C++17
35 / 100
138 ms24008 KiB
#include "islands.h" #include<bits/stdc++.h> using namespace std; #define pb push_back #define fr first #define sc second #define mp make_pair #define all(x) x.begin(),x.end() const int maxn = 2e5+10; int n, m, Ug[maxn], Vg[maxn], grin[maxn], grout[maxn], atv[maxn]; vector<int> gin[maxn], gout[maxn]; variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) { n = N; m = M; int ans = 0; for(int i = 0; i < m; i++) { Ug[i] = U[i]; Vg[i] = V[i]; gout[Ug[i]].pb(i); gin[Vg[i]].pb(i); } queue<int> qout0; for(int i = 0; i < m; i++) { grin[Vg[i]]++; grout[Ug[i]]++; } for(int i = 0; i < n; i++) { atv[i] = 1; if(grout[i] == 0) qout0.push(i); } int x = 0; while(x != -1) { while(qout0.size()) { int v = qout0.front(); atv[v] = 0; qout0.pop(); // delete v, I just need to delete the in edges for(auto id : gin[v]) { int u = Ug[id]; grout[u]--; if(grout[u] == 0) { qout0.push(u); } } } if(grout[x] == 0) { x = -1; } else if(grout[x] == 1) { //just use it // delete the out edge, them it will delete the in edges automatically for(auto id : gout[x]) { int v = Vg[id]; if(atv[v]) { grin[v]--; grout[x]--; qout0.push(x); x = v; break; } } } else { ans = 1; break; } } if(ans) { 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...