이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "islands.h"
#include <variant>
#include <vector>
#include <algorithm>
#include <assert.h>
#include <map>
//#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
int n,m;
map<int,vector<int>> c[100005];
vector<int> muchii[100005];
vector<int> sol;
void n2(int x,int y)
{
int A=c[1][0][0];
int B=c[0][1][0];
int C=c[0][1][1];
vector<int> aux={B,A,C,B,A,C};
for(int i:aux)
sol.push_back(i);
}
bool use[100005];
vector<int> lant;
bool good;
bool inst[100005];
int from[100005];
int who;
void s1(int nod)
{
if(good)
return;
use[nod]=1;
inst[nod]=1;
for(int i:muchii[nod])
{
if(!inst[i])
{
if(c[nod][i].size()>=2&&c[i][nod].size()>=1)
{
who=i;
good=1;
int x=nod;
while(true)
{
lant.push_back(x);
if(x==0)
break;
x=from[x];
}
return;
}
if(!use[i])
{
from[i]=nod;
s1(i);
}
}
}
inst[nod]=0;
}
void build(int x,int y,int z)
{
assert(x>=0&&y>=0&&z>=0);
int A=c[x][y][0];
int B=c[y][x][0];
int C=c[x][z][0];
int D=c[z][x][0];
if(y==z)
{
C=c[x][z][1];
D=c[z][x][1];
}
vector<int> aux={A,B,C,D,B,A,D,C};
for(int i:aux)
sol.push_back(i);
}
int A,B;
void s2(int nod)
{
if(good)
return;
use[nod]=1;
inst[nod]=1;
vector<int> dub;
for(int i:muchii[nod])
{
if(!inst[i])
{
for(int j=1;dub.size()<2&&j<=min(c[nod][i].size(),c[i][nod].size());j++)
dub.push_back(i);
}
}
if(dub.size()>=2)
{
good=1;
A=dub[0];
B=dub[1];
int x=nod;
while(true)
{
lant.push_back(x);
if(x==0)
break;
x=from[x];
}
return;
}
for(int i:muchii[nod])
{
if(good)
return;
if(!use[i])
{
from[i]=nod;
s2(i);
}
}
inst[nod]=0;
}
std::variant<bool, std::vector<int>> find_journey(int N, int M, std::vector<int> U, std::vector<int> V)
{
n=N;
m=M;
for(int i=0;i<m;i++)
{
int a=U[i],b=V[i];
c[a][b].push_back(i);
if(c[a][b].size()==1)
muchii[a].push_back(b);
}
s1(0);
if(good)
{
reverse(lant.begin(),lant.end());
for(int i=1;i<lant.size();i++)
sol.push_back(c[lant[i-1]][lant[i]][0]);
n2(lant.back(),who);
reverse(lant.begin(),lant.end());
for(int i=1;i<lant.size();i++)
sol.push_back(c[lant[i]][lant[i-1]][0]);
return sol;
}
for(int i=0;i<n;i++)
{
use[i]=0;
inst[i]=0;
}
lant.clear();
s2(0);
if(good)
{
reverse(lant.begin(),lant.end());
for(int i=1;i<lant.size();i++)
sol.push_back(c[lant[i-1]][lant[i]][0]);
build(lant.back(),A,B);
reverse(lant.begin(),lant.end());
for(int i=1;i<lant.size();i++)
sol.push_back(c[lant[i]][lant[i-1]][0]);
return sol;
}
return false;
}
컴파일 시 표준 에러 (stderr) 메시지
islands.cpp: In function 'void s2(int)':
islands.cpp:91:40: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
91 | for(int j=1;dub.size()<2&&j<=min(c[nod][i].size(),c[i][nod].size());j++)
| ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:138:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
138 | for(int i=1;i<lant.size();i++)
| ~^~~~~~~~~~~~
islands.cpp:142:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
142 | for(int i=1;i<lant.size();i++)
| ~^~~~~~~~~~~~
islands.cpp:156:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
156 | for(int i=1;i<lant.size();i++)
| ~^~~~~~~~~~~~
islands.cpp:160:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
160 | for(int i=1;i<lant.size();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... |