# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1024772 | vjudge1 | Thousands Islands (IOI22_islands) | C++17 | 13 ms | 31612 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>
#include <variant>
#define f first
#define s second
#define ent '\n'
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 12;
const int mod = 1e9 + 2022;
map<int, int> a[maxn];
vector<int> g[maxn];
int used[maxn];
vector<int> cyc, ord, ver, pref;
int n, m;
void dfs(int v){
used[v] = 1;
ver.push_back(v);
for(int to:g[v]){
if(used[to] == 1){
cyc = ord;
cyc.push_back(a[v][to]);
int pos = 0;
for(int i=0;i<ver.size();i++){
if(ver[i] == to){
pos = i;
break;
}
if(i > 0){
pref.push_back(ord[i-1]);
}
}
}
if(!used[to]){
ord.push_back(a[v][to]);
dfs(to);
ord.pop_back();
}
}
used[v] = 2;
ver.pop_back();
}
variant<bool, vector<int>> find_journey(int N, int M, vector<int> u, vector<int> v){
n = N, m = M;
for(int i=0;i<m;i+=2){
a[u[i]][v[i]] = i;
g[u[i]].push_back(v[i]);
}
dfs(0);
if(cyc.size() == 0){
return false;
}
vector<int> ans = pref;
reverse(cyc.begin(), cyc.end());
for(int i=0;i<pref.size();i++){
cyc.pop_back();
}
reverse(cyc.begin(), cyc.end());
for(int x:cyc){
ans.push_back(x);
}
for(int x:cyc){
ans.push_back(x+1);
}
reverse(cyc.begin(), cyc.end());
for(int x:cyc){
ans.push_back(x);
}
for(int x:cyc){
ans.push_back(x+1);
}
reverse(pref.begin(), pref.end());
for(int x:pref){
ans.push_back(x);
}
return ans;
}
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... |