# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1149636 | byunjaewoo | Thousands Islands (IOI22_islands) | C++20 | 21 ms | 4932 KiB |
#include "islands.h"
#include <bits/stdc++.h>
using namespace std;
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
vector<pair<int, int>> adj[1010];
bool chk[1010], chk2[1010];
int prv[1010], pw[1010];
fill(chk, chk+N, false), fill(chk2, chk2+N, false);
fill(prv, prv+N, -1), fill(pw, pw+N, -1);
prv[0]=0;
for(int i=0; i<M; i+=2) adj[U[i]].push_back({V[i], i});
vector<int> ret;
function<void(int)> dfs=[&](int curr) {
chk[curr]=true, chk2[curr]=true;
for(auto [next, k]:adj[curr]) {
if(!chk[next]) prv[next]=curr, pw[next]=k, dfs(next);
else if(chk2[next]) {
ret.push_back(k+1);
for(int i=curr; i!=next; i=prv[i]) ret.push_back(pw[i]+1);
ret.push_back(k);
for(int i=curr; i!=next; i=prv[i]) ret.push_back(pw[i]);
vector<int> tmp;
tmp.push_back(k);
for(int i=curr; i!=next; i=prv[i]) tmp.push_back(pw[i]);
tmp.push_back(k+1);
for(int i=curr; i!=next; i=prv[i]) tmp.push_back(pw[i]+1);
reverse(tmp.begin(), tmp.end());
for(int i:tmp) ret.push_back(i);
for(int i=next; i; i=prv[i]) ret.push_back(pw[i]);
# | 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... |