이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
#include "islands.h"
const int N = 1e3 + 5;
vector<int> nodes, cycle, adj[N];
vector<bool> vis(N);
void dfs(int node){
if(cycle.size() > 0) return;
nodes.pb(node);
vis[node] = 1;
for(auto itr: adj[node]){
if(!vis[itr]){
dfs(itr);
}
if(itr == 0 && nodes.size() > 2) cycle = nodes;
if(cycle.size() > 0) return;
}
nodes.pop_back();
}
std::variant<bool, std::vector<int>> find_journey(int N, int M, std::vector<int> U, std::vector<int> V) {
if(N == 2){ // subtask 1
vector<int> c[2];
for(int i = 0; i < M; i++){
if(U[i] == 0) c[0].pb(i);
else c[1].pb(i);
}
if(c[0].size() > 1 && c[1].size() > 0){
int x = c[0][0], y = c[0][1], z = c[1][0];
vector<int> ans = {x, z, y, x, z, y};
return ans;
}
else return false;
}
if(N <= 400){ // subtask 2
vector<vector<int> > cnt(N, vector<int>(N, -1));
for(int i = 0; i < M; i++){
cnt[U[i]][V[i]] = i;
}
bool ok = 1;
for(int i = 0; i < N; i++){
for(int j = 0; j < N; j++){
if(i == j) continue;
if(cnt[i][j] == -1) ok = 0;
}
}
if(ok){
int c0 = cnt[0][1];
int c1 = cnt[1][2];
int c2 = cnt[2][0];
int c3 = cnt[0][2];
int c4 = cnt[2][1];
int c5 = cnt[1][0];
vector<int> ans = {c0, c1, c2, c3, c4, c5, c2, c1, c0, c5, c4, c3};
return ans;
}
}
bool subtask3 = 1;
vector<vector<int> > num(N, vector<int>(N));
for(int i = 0; i < M; i++){
adj[U[i]].pb(V[i]);
num[U[i]][V[i]] = i;
if(i % 2 == 0 && (U[i] != V[i+1] || V[i] != U[i+1])){
subtask3 = 0;
}
}
if(subtask3){
dfs(0);
if(!cycle.size()){
return false;
}
else{
vector<int> c1, c2;
for(int i = 0; i < cycle.size(); i++){
c1.pb(num[cycle[i]][cycle[(i + 1) % cycle.size()]]);
}
for(int i = cycle.size()-1; i >= 0; i--){
c2.pb(num[cycle[(i + 1) % cycle.size()]][cycle[i]]);
}
vector<int> ans;
for(auto itr: c1){
ans.pb(itr);
}
for(auto itr: c2){
ans.pb(itr);
}
reverse(c1.begin(), c1.end());
reverse(c2.begin(), c2.end());
for(auto itr: c1){
ans.pb(itr);
}
for(auto itr: c2){
ans.pb(itr);
}
return ans;
}
}
return false;
}
/*
int main() {
int N, M;
assert(2 == scanf("%d %d", &N, &M));
std::vector<int> U(M), V(M);
for (int i = 0; i < M; ++i) {
assert(2 == scanf("%d %d", &U[i], &V[i]));
}
std::variant<bool, std::vector<int>> result = find_journey(N, M, U, V);
if (result.index() == 0) {
printf("0\n");
if (std::get<bool>(result)) {
printf("1\n");
} else {
printf("0\n");
}
} else {
printf("1\n");
std::vector<int> &canoes = std::get<std::vector<int>>(result);
printf("%d\n", static_cast<int>(canoes.size()));
for (int i = 0; i < static_cast<int>(canoes.size()); ++i) {
if (i > 0) {
printf(" ");
}
printf("%d", canoes[i]);
}
printf("\n");
}
return 0;
}
*/
컴파일 시 표준 에러 (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:90:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for(int i = 0; i < cycle.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... |