제출 #1058512

#제출 시각아이디문제언어결과실행 시간메모리
1058512tolbi수천개의 섬 (IOI22_islands)C++17
0 / 100
1 ms604 KiB
#include "islands.h" #include <bits/stdc++.h> using namespace std; struct DSU{ vector<int> par; DSU(int n){ par.resize(n); iota(par.begin(), par.end(), 0); } int find(int node){ if (par[node]==node) return node; return par[node]=find(par[node]); } void merge(int a, int b){ a=find(a); b=find(b); par[a]=b; } }; 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>>> arr(N); for (int i = 0; i < M; i+=2){ arr[U[i]].push_back({V[i],i}); } vector<bool> vis(N,false); vector<pair<int,int>> par(N,{-1,-1}); vector<int> dept(N,0); function<void(int)> dfs = [&](int node)->void{ if (vis[node]) return; vis[node]=true; for (auto it : arr[node]){ if (vis[it.first]) continue; dept[it.first]=dept[node]+1; par[it.first]={node,it.second}; dfs(it.first); } }; dfs(0); DSU dsu(N); for (int i = 0; i < N; i++){ if (!vis[i]) continue; for (auto it : arr[i]){ if (!vis[it.first]) continue; if (dsu.find(i)==dsu.find(it.first)){ return vector<int>(1,23); } else { dsu.merge(i,it.first); break; } } } 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...