This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)){
//oha ans buldum
return vector<int>(1,23);
}
else {
dsu.merge(i,it.first);
}
}
}
return false;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |