제출 #955801

#제출 시각아이디문제언어결과실행 시간메모리
955801n1k수천개의 섬 (IOI22_islands)C++17
19.25 / 100
38 ms9684 KiB
#include "islands.h" #include <bits/stdc++.h> using namespace std; vector<vector<array<int, 2>>> g, rg; vector<int> color, par, del, deg; map<int, int> cache; int dfs(int u, int p){ par[u] = p; del[u] = 1; int out_deg = 0; for(auto [v, e]:g[u]){ out_deg += 1-del[v]; } if(out_deg>1) return 1; bool ok = 0; for(auto [v, e]:g[u]){ if(del[v]) continue; ok |= dfs(v, u); } return ok; } std::variant<bool, std::vector<int>> find_journey(int N, int M, std::vector<int> U, std::vector<int> V) { g.assign(N, {}); rg.assign(N, {}); color.assign(N, {}); par.assign(N, {}); del.assign(N, {}); deg.assign(N, {}); for(int i=0; i<M; i++){ g[U[i]].push_back({V[i], i}); rg[V[i]].push_back({U[i], i}); } queue<int> q; for(int i=0; i<N; i++){ deg[i]=g[i].size(); if(deg[i]==0){ q.push(i); } } while(q.size()){ auto u = q.front(); q.pop(); del[u]=1; for(auto [v, e]:rg[u]){ if(--deg[v]==0){ q.push(v); } } } return dfs(0, -1)==1; }
#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...