Submission #1009269

#TimeUsernameProblemLanguageResultExecution timeMemory
1009269CSQ31Thousands Islands (IOI22_islands)C++17
11.90 / 100
36 ms35464 KiB
#include "islands.h" #include<bits/stdc++.h> #include <variant> #include <vector> using namespace std; #define sz(a) (int)(a.size()) #define pb push_back #define fi first #define se second typedef pair<int,int> pii; const int MAXN = 5e5+5; bool dead[MAXN],mark[MAXN]; int outdeg[MAXN]; vector<pii>g[MAXN],gr[MAXN]; void upd(int v){ while(!g[v].empty() && dead[g[v].back().se])g[v].pop_back(); } variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V){ for(int i=0;i<M;i++){ gr[V[i]].pb({U[i],i}); g[U[i]].pb({V[i],i}); outdeg[U[i]]++; } vector<int>del; for(int i=0;i<N;i++){ //cout<<i<<" "<<sz(g[i])<<'\n'; if(g[i].empty()){ del.pb(i); mark[i] = 1; } } int cur = 0; while(true){ if(mark[cur])return false; while(!del.empty()){ vector<int>tmp; for(int u:del){ for(pii x:gr[u]){ int v = x.fi; outdeg[v]--; dead[x.se] = 1; if(!outdeg[v]){ tmp.pb(v); mark[v] = 1; } } } del = tmp; } if(mark[cur])return false; upd(cur); if(outdeg[cur] > 1)return true; else if(outdeg[cur] == 0)return false; else{ del.push_back(cur); mark[cur] = 1; upd(cur); cur = g[cur].back().fi; } } }
#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...