# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
830790 | tolbi | Thousands Islands (IOI22_islands) | C++17 | 28 ms | 7956 KiB |
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 <bits/stdc++.h>
using namespace std;
#define coutarr(x) for (auto &it : x) cout<<it<<" ";cout<<endl;
#include "islands.h"
variant<bool, vector<int>> solve(int n, int m, vector<int> u, vector<int> v, vector<int> _indis) {
vector<bool> vis(n,false);
vector<int> ansarr;
vector<vector<pair<int,int>>> arr(n);
for (int i = 0; i < m; ++i)
{
arr[u[i]].push_back({v[i],_indis[i]});
}
auto dfs = [&](int node, auto dfs)->bool{
if (vis[node]) {
return true;
}
vis[node]=true;
ansarr.push_back(node);
for (int i = 0; i < arr[node].size(); i++){
if (dfs(arr[node][i].first,dfs)) return true;
}
ansarr.pop_back();
return false;
};
if (!dfs(0,dfs)) return false;
return true;
}
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
int crr = 0;
vector<int> ind(N,-1);
vector<int> indarr;
vector<vector<int>> arr(N);
for (int i = 0; i < M; ++i)
{
arr[U[i]].push_back(V[i]);
}
auto dfs = [&](int node, auto dfs)->void{
if (ind[node]!=-1) return;
ind[node]=crr++;
for (int i = 0; i < arr[node].size(); i++){
dfs(arr[node][i],dfs);
}
};
dfs(0,dfs);
vector<int> asu;
vector<int> asv;
for (int i = 0; i < M; i++){
if (ind[U[i]]==-1 || ind[V[i]]==-1) continue;
asu.push_back(ind[U[i]]);
asv.push_back(ind[V[i]]);
indarr.push_back(i);
}
return solve(crr,asu.size(),asu,asv,indarr);
}
Compilation message (stderr)
# | 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... |