제출 #837188

#제출 시각아이디문제언어결과실행 시간메모리
837188ymm수천개의 섬 (IOI22_islands)C++17
10.15 / 100
41 ms8820 KiB
#include "islands.h" #include <bits/stdc++.h> #define Loop(x,l,r) for (ll x = (l); x < (r); ++x) typedef long long ll; using namespace std; const int N = 100'010; int height[N], mnup[N]; vector<int> A[N]; bool vis[N]; bool anc[N]; int cnt[N]; int kooft[N]; int par[N]; bool marg[N]; void mark(int v, int u) { while (u != par[v]) { if (marg[u]) throw 1; marg[u] = 1; u = par[u]; } } void dfs1(int v, int p, int h) { par[v] = p; vis[v] = 1; anc[v] = 1; height[v] = h; mnup[v] = N; for (int u : A[v]) { if (anc[u]) { mnup[v] = min(mnup[v], height[u]); kooft[u]--; mark(u, v); } if (vis[u]) continue; dfs1(u, v, h+1); mnup[v] = min(mnup[v], mnup[u]); } anc[v] = 0; } void make_count() { vector<int> vec = {0}; cnt[0] = 1; while (vec.size()) { int v = vec.back(); vec.pop_back(); vis[v] = 1; for (int u : A[v]) { if (!vis[u]) { cnt[u] += cnt[v]; //cnt[u] = min(cnt[u], 2); if (!--kooft[u]) vec.push_back(u); } } } } std::variant<bool, std::vector<int>> find_journey( int N, int M, std::vector<int> U, std::vector<int> V) { Loop (i,0,M) { A[U[i]].push_back(V[i]); kooft[V[i]]++; } try { dfs1(0, -1, 0); } catch(int) { return true; } memset(vis, 0, sizeof(vis)); Loop (i,0,N) make_count(); Loop (i,0,N) { if (cnt[i] >= 2 && mnup[i] <= height[i]) 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...