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 "islands.h"
#include <bits/stdc++.h>
using namespace std;
int n,m;
vector<int> u,v;
vector<int> vis(1e5+3,0);
vector<int> par(1e5+3,-1);
vector<vector<int>> adj(1e5+3,vector<int>(0));
variant<bool, std::vector<int>>
find_journey(int N, int M, vector<int> U, vector<int> V) {
n=N,m=M,u=U,v=V;
if (n==2) {
vector<int> fv,sv;
for (int x=0; x<m; ++x) if (u[x]==0) fv.push_back(x); else sv.push_back(x);
int f=fv.size(), s=sv.size();
if (f>=2 && s) {
vector<int> r={fv[0],sv[0],fv[1],fv[0],sv[0],fv[1]};;
return r;
}
else return false;
}
if (n<=400 && m==n*(n-1)) {
int a,b,c,d;
for (int i=0; i<m; ++i) {
if (u[i]==0 && v[i]==1) a=i;
if (u[i]==0 && v[i]==2) b=i;
if (u[i]==1 && v[i]==0) c=i;
if (u[i]==2 && v[i]==0) d=i;
}
vector<int> r = {a,c,b,d,c,a,d,b};
return r;
}
int _p3=1, _p4=1;
for (int i=0; i<m; i+=2) {
_p3&=((u[i]==v[i+1])&&(v[i]==u[i+1]));
_p4&=((u[i]==u[i+1])&&(v[i]==v[i+1]));
}
if (_p3) {
vector<int> deg(1e5+3,0);
for (int i=0; i<m; i+=2) {
deg[u[i]]++;
deg[v[i]]++;
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
int mx=0;
for (auto x:deg) mx=max(mx,x);
if (deg[0]>=2) {
int a=-1,b=-1,c=-1,d=-1;
int f=-1,s=-1;
for (auto x:adj[0]) {
if (f==-1) f=x;
else {s=x; break;}
}
for (int i=0; i<m; ++i) {
if (u[i]==0 && v[i]==f) a=i;
if (u[i]==0 && v[i]==s) b=i;
if (u[i]==f && v[i]==0) c=i;
if (u[i]==s && v[i]==0) d=i;
}
vector<int> r = {a,c,b,d,c,a,d,b};
return r;
}
if (mx<3) return false;
vis[0]=1;
queue<int> q; q.push(0);
while (!q.empty()) {
int x=q.front(); q.pop();
if (deg[x]>=3) {
vector<int> r;
int a,b,c,d;
vector<int> path;
int p=x;
while (p!=0) {
for (int i=0; i<m; ++i) {
if (u[i]==par[p] && v[i]==p) {
path.push_back(i);
break;
}
}
p=par[p];
}
for (int i=path.size()-1; i>=0; --i) r.push_back(path[i]);
int f=-1, s=-1;
for (auto y:adj[x]) {
if (y==par[x]) continue;
if (f==-1) f=y;
else {s=y; break;}
}
for (int i=0; i<m; ++i) {
if (u[i]==x && v[i]==f) a=i;
if (u[i]==x && v[i]==s) b=i;
if (u[i]==f && v[i]==x) c=i;
if (u[i]==s && v[i]==x) d=i;
}
vector<int> paiu={a,c,b,d,c,a,d,b};
for (auto x:paiu) r.push_back(x);
for (int i=0; i<path.size(); ++i) r.push_back(path[i]);
return r;
}
for (auto y:adj[x]) {
if (!vis[y]) {
q.push(y);
vis[y]=1;
par[y]=x;
}
}
}
return false;
}
}
Compilation message (stderr)
islands.cpp: In function 'std::variant<bool, std::vector<int, std::allocator<int> > > find_journey(int, int, std::vector<int>, std::vector<int>)':
islands.cpp:114:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
114 | for (int i=0; i<path.size(); ++i) r.push_back(path[i]);
| ~^~~~~~~~~~~~
islands.cpp:131:1: warning: control reaches end of non-void function [-Wreturn-type]
131 | }
| ^
islands.cpp:112:42: warning: 'd' may be used uninitialized in this function [-Wmaybe-uninitialized]
112 | vector<int> paiu={a,c,b,d,c,a,d,b};
| ^
islands.cpp:112:42: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:112:42: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:112:42: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:36:37: warning: 'd' may be used uninitialized in this function [-Wmaybe-uninitialized]
36 | vector<int> r = {a,c,b,d,c,a,d,b};
| ^
islands.cpp:36:37: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:36:37: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:36:37: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
# | 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... |