# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
796458 | ln_e | Thousands Islands (IOI22_islands) | C++17 | 43 ms | 5188 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> //Andrei Alexandru a.k.a Sho
#include "islands.h"
using ll=long long;
using ld=long double;
int const INF=1000000005;
ll const LINF=1000000000000000005;
ll const mod=1000000007;
ld const PI=3.14159265359;
ll const MAX_N=3e5+5;
ld const EPS=0.00000001;
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define sz(a) (int)a.size()
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vector<ll>g[1005];
map<ll,ll>viz;
int dfs(ll node){
viz[node]=1;
for(auto it : g[node]){
if(viz[it]==1){
return 1;
}
if(viz[it]==0){
if(dfs(it)){
return 1;
}
}
}
viz[node]=2;
return 0;
}
std::variant<bool, std::vector<int>> find_journey(
int N, int M, std::vector<int> U, std::vector<int> V) {
ll verif=1;
for(ll i=0;i<M;i+=2){
if(U[i]!=V[i+1]&&U[i+1]!=V[i]){
verif=0;
}
}
if (N == 2){
vector<ll>g[3];
for(ll i=0;i<M;i++)
{
g[U[i]].pb(i);
}
if(g[0].size()>=2&&g[1].size()>=1){
vector<int>ans;
ans.pb(g[0][0]);
ans.pb(g[1][0]);
ans.pb(g[0][1]);
ans.pb(g[0][0]);
ans.pb(g[1][0]);
ans.pb(g[0][1]);
return ans;
}else return false;
}else if(N<=400&&M==N*(N-1)){
ll indx[10];
if(N<3){
return false;
}
for(ll i=0;i<M;i++){
if(U[i]==0&&V[i]==1){
indx[1]=i;
}else if(U[i]==1&&V[i]==0){
indx[2]=i;
}else if(U[i]==1&&V[i]==2){
indx[3]=i;
}else if(U[i]==2&&V[i]==1){
indx[4]=i;
}else if(U[i]==0&&V[i]==2){
indx[5]=i;
}else if(U[i]==2&&V[i]==0){
indx[6]=i;
}
}
vector<int>ans;
ans.pb(indx[1]);
ans.pb(indx[3]);
ans.pb(indx[4]);
ans.pb(indx[1]);
ans.pb(indx[5]);
ans.pb(indx[3]);
ans.pb(indx[4]);
ans.pb(indx[5]);
return ans;
}else if(N<=1000&&verif){
map<ll,ll>deg;
for(ll i=0;i<M;i+=2)
{
g[U[i]].pb(V[i]);
g[V[i]].pb(U[i]);
deg[U[i]]++;
deg[V[i]]++;
}
queue<ll>q;
q.push(0);
while(!q.empty()){
ll x=q.front();
q.pop();
if(deg[x]>=3){
return true;
}
for(auto it : g[x]){
if(viz[it]==0){
q.push(it);
viz[it]=1;
}
}
}
return false;
}else {
for(ll i=0;i<M;i+=2)
{
g[U[i]].pb(V[i]);
}
ll check=dfs(0);
for(ll i=0;i<N;i++)
{
g[i].clear();
}
for(ll i=1;i<M;i+=2){
g[U[i]].pb(V[i]);
}
check|=dfs(0);
if(check==1){
return true;
}else return false;
}
}
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... |