| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1370850 | Andrey | 수천개의 섬 (IOI22_islands) | C++17 | 0 ms | 0 KiB |
#include "islands.h"
#include<bits/stdc++.h>
#include<variant>
using namespace std;
int n,m;
const int MAXN = 100010;
vector<pair<int,int>> haha[MAXN];
std::variant<bool, std::vector<int>> find_journey(int N, int M, std::vector<int> u, std::vector<int> v) {
n = N;
m = M;
vector<int> br(n);
for(int i = 0; i < m; i++) {
haha[u[i]].push_back({v[i],i});
haha[v[i]].push_back({u[i],i});
br[v[i]]++;
}
int y = 0;
vector<pair<int,int>> yo(n,{-1,-1});
vector<bool> bruh(n,true);
while(true) {
vector<int> idk(0);
vector<int> wow(0);
idk.push_back(y);
wow.push_back(y);
for(int i = 0; i < idk.size(); i++) {
int a = idk[i];
for(pair<int,int> u: haha[a]) {
int v = u.first;
if(a == y) {
yo[v] = {u.second,-1};
}
else {
if(yo[a].second != -1) {
yo[v] = yo[a];
}
else if(yo[a].first != -1) {
if(yo[v].first == -1) {
yo[v] = {yo[a].first,-1};
}
else if(yo[v].second == -1) {
yo[v] = {yo[v].first,yo[v].second};
}
}
}
br[v]--;
if(br[v] == 0) {
idk.push_back(v);
}
wow.push_back(v);
}
}
int x = -1,p = -1;
for(int v: wow) {
if(br[v] > 0) {
if(yo[v].second != -1) {
return true;
}
if(yo[v].first != -1) {
if(x == -1) {
x = yo[v].first;
p = a;
}
else {
return true;
}
}
}
}
for(int v: idk) {
bruh[v] = false;
}
y = p;
}
}
