제출 #628322

#제출 시각아이디문제언어결과실행 시간메모리
628322MarkBcc168Thousands Islands (IOI22_islands)C++17
0 / 100
1112 ms724020 KiB
#include <bits/stdc++.h>
using namespace std;

int reverse_edge(int ind){
    if(ind % 2 == 0) return ind+1;
    else return ind-1;
}

std::variant<bool, std::vector<int>> find_journey(int n, int m, vector<int> u, vector<int> v){
    vector<pair<int,int>> adj[n];
    for(int i=0; i<m; i+=2){
        adj[u[i]].push_back(make_pair(v[i],i));
        adj[v[i]].push_back(make_pair(u[i],i+1));
    }
    //find cycle
    vector<int> prev(n,-1), st(1,0);
    vector<bool> vis(n, false);
    bool found = false;
    while(!st.empty()){
        int v = st[st.size()-1];
        st.pop_back();
        vis[v] = true;
        for(pair<int,int> p : adj[v]){
            int u = p.first;
            if(u==0){found = true; prev[0] = p.second; break;}
            if(vis[u]) continue;
            prev[u] = p.second;
            st.push_back(u);
        }
        if(found) break;
    }
    if(!found) return false;
    vector<int> cyc;
    int x = 0;
    do{
        cyc.push_back(prev[x]);
        x = u[prev[x]];
    }while(x != 0);
    reverse(cyc.begin(), cyc.end());

    //now print the journey
    vector<int> c;
    for(int e : cyc){
        c.push_back(e);
    }
    for(int e : cyc){
        c.push_back(reverse_edge(e));
    }
    reverse(cyc.begin(), cyc.end());
    for(int e : cyc){
        c.push_back(e);
    }
    for(int e : cyc){
        c.push_back(reverse_edge(e));
    }
}

컴파일 시 표준 에러 (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:56:1: warning: control reaches end of non-void function [-Wreturn-type]
   56 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...