이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "islands.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define en cout << '\n'
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define vi vector<int>
#define ff first
#define ss second
const int N = 1e5+10;
int n, m;
vector<pair<int, int>> g[N];
vector<int> euler, cyc;
vector<bool> good;
bool is_cyc = 0;
bool dfs(int v, int par, vector<bool> &vis){
vis[v] = 1;
euler.pb(v);
for(auto U: g[v]){
int u = U.ss;
if(vis[u] && u != par){
euler.pb(u);
cyc.pb(u);
is_cyc = 1;
return 1;
}
if(good[v] && good[u]){
}
if(!vis[u]){
bool ok = dfs(u, v, vis);
if(is_cyc) cyc.pb(v);
if(ok && v == cyc.back()){
is_cyc = 0;
}
if(ok) return 1;
}
}
euler.pop_back();
return 0;
}
std::variant<bool, std::vector<int>> find_journey(int nn, int mm, std::vector<int> U, std::vector<int> V) { n=nn, m=mm;
vector<vi> C(nn);
map<pii, vi> A;
good.resize(n);
for(int i = 0; i < mm; ++i){
C[U[i]].pb(i);
g[U[i]].pb({i, V[i]});
A[{U[i], V[i]}].pb(i);
if(A[{U[i], V[i]}].size() > 1) good[U[i]] = good[V[i]] = 1;
}
for(int i = 1; i < n; ++i){
if(A[{0, i}].size() > 1 && A[{i, 0}].size() > 0){
return vi{A[{0, i}][0], A[{i, 0}][0], A[{0, i}][1], A[{0, i}][0], A[{i, 0}][0], A[{0, i}][1]};
}
}
// if(!(C[0].size() > 1 && C[1].size() > 0)) return false;
vector<bool> vis(n);
bool ok = dfs(0, 0, vis);
if(!ok) return false;
vi res;
for(int i = 0; i + 1 < euler.size(); ++i){
res.pb(A[{euler[i], euler[i + 1]}][0]);
}
reverse(all(cyc));
for(int i = 0; i + 1 < cyc.size(); ++i){
cyc.pb(A[{cyc[i], cyc[i + 1]}][0]);
}
for(int i = 0; i + 1 < cyc.size(); ++i){
cyc.pb(A[{euler[i], euler[i + 1]}][1]);
}
reverse(all(res));
for(int i = 0; i + 1 < euler.size(); ++i){
res.pb(A[{euler[i], euler[i + 1]}][0]);
}
return res;
}
컴파일 시 표준 에러 (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:65:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int i = 0; i + 1 < euler.size(); ++i){
| ~~~~~~^~~~~~~~~~~~~~
islands.cpp:69:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for(int i = 0; i + 1 < cyc.size(); ++i){
| ~~~~~~^~~~~~~~~~~~
islands.cpp:72:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for(int i = 0; i + 1 < cyc.size(); ++i){
| ~~~~~~^~~~~~~~~~~~
islands.cpp:76:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for(int i = 0; i + 1 < euler.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... |