이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "islands.h"
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#include <variant>
#include <vector>
using namespace std;
vector<pair<int, int > >child[5005];
int devuelta[5005];
vector<pair<int, int > > adj[5005];
vector<int>tempRoute;
vector<int>rt;
bool dfs(int node, int parent){
for(int i = 0 ; i < adj[node].size() ; i ++){
if(adj[node][i].ff == parent)continue;
child[node].pb(adj[node][i]);
}
if(child[node].size() >= 2){
int a = child[node][0].ss;
int b = devuelta[child[node][0].ss];
int c = child[node][1].ss;
int d = devuelta[c];
tempRoute = {a, b, c, d, b, a, d, c};
return true;
}
for(auto i : child[node]){
if(dfs(i.ff, node)){
rt.pb(i.ss);
return true;
}
}
return false;
}
std::variant<bool, std::vector<int>> find_journey(
int N, int M, std::vector<int> U, std::vector<int> V) {
int cuenta[N][N];
vector<int>parejas[N][N];
for(int i = 0 ; i < N ; i ++){
for(int j = 0 ; j < N ; j ++){
cuenta[i][j] = 0;
}
}
for(int i = 0 ; i < M ; i ++ ){
cuenta[U[i]][V[i]] ++ ;
parejas[U[i]][V[i]].pb(i);
adj[U[i]].pb({V[i], i});
}
if (N == 2) {
if(cuenta[0][1] >= 2 and cuenta[1][0] >= 1){
int a = parejas[0][1][0];
int b = parejas[1][0][0];
int c = parejas[0][1][1];
vector<int>ans = {a, b, c, a, b, c};
return ans;
}
return false;
}else{
bool case3 = true;
if( M % 2 == 1)case3 = false;
for(int i = 0 ; i < M ; i += 2){
if(U[i] != V[i+1] or V[i] != U[i] + 1)case3 = false;
devuelta[i] = i+1;
devuelta[i+1] = i;
}
if(!case3){
int a = parejas[0][1][0];
int b = parejas[1][0][0];
int c = parejas[0][2][0];
int d = parejas[2][0][0];
vector<int>ans = {a, b, c, d, b, a, d, c};
return ans;
}else{
if(!dfs(0, -1))return false;
vector<int>ans = rt;
reverse(ans.begin(), ans.end());
for(auto i : tempRoute)ans.pb(i);
for(auto i : rt)ans.pb(i);
return ans;
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
islands.cpp: In function 'bool dfs(int, int)':
islands.cpp:16:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for(int i = 0 ; i < adj[node].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... |