# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
939240 | irmuun | Thousands Islands (IOI22_islands) | C++17 | 1116 ms | 1171484 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 "islands.h"
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
variant<bool,vector<int>>find_journey(int n,int m,vector<int>u,vector<int>v){
bool ok=false;
vector<int>ans,road;
vector<pair<int,int>>adj[n];
for(int i=0;i<m;i+=2){
adj[u[i]].pb({v[i],i});
adj[v[i]].pb({u[i],i});
}
int cur=0,par=-1;
while(true){
int x=0,y=1;
if(par==-1){
if(adj[cur].size()>=2){
ans.pb(adj[cur][0].ss);
ans.pb(adj[cur][0].ss+1);
ans.pb(adj[cur][1].ss);
ans.pb(adj[cur][1].ss+1);
ans.pb(adj[cur][0].ss+1);
ans.pb(adj[cur][0].ss);
ans.pb(adj[cur][1].ss+1);
ans.pb(adj[cur][1].ss);
}
if(adj[cur].size()==0) return false;
ans.pb(adj[cur][0].ss);
road.pb(adj[cur][0].ss);
par=cur;
cur=adj[cur][0].ff;
}
else{
int i=0,j=1;
if(adj[cur].size()>=3){
if(adj[cur][0].ff==par) i=1,j=2;
else if(adj[cur][1].ff==par) j=2;
ans.pb(adj[cur][i].ss);
ans.pb(adj[cur][i].ss+1);
ans.pb(adj[cur][j].ss);
ans.pb(adj[cur][j].ss+1);
ans.pb(adj[cur][i].ss+1);
ans.pb(adj[cur][i].ss);
ans.pb(adj[cur][j].ss+1);
ans.pb(adj[cur][j].ss);
}
if(adj[cur].size()==1) return false;
if(adj[cur][0].ff==par){
ans.pb(adj[cur][1].ss);
road.pb(adj[cur][1].ss);
par=cur;
cur=adj[cur][1].ff;
}
else{
ans.pb(adj[cur][0].ss);
road.pb(adj[cur][0].ss);
par=cur;
cur=adj[cur][0].ff;
}
}
}
for(int i=(int)road.size()-1;i>=0;i--){
ans.pb(road[i]+1);
}
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... |