제출 #1359447

#제출 시각아이디문제언어결과실행 시간메모리
1359447opeleklanos수천개의 섬 (IOI22_islands)C++20
22.75 / 100
13 ms5148 KiB
#include <iostream>
#include <vector>
#include <variant>
using namespace std;

vector<vector<pair<int, int>>> adj;
vector<int> path;

void dfs(int st, int par){
    if((par == -1 && adj[st].size() >= 2) || (par!=-1 && adj[st].size()>=3)){
        int a = -1, b = -1, c = -1, d = -1;
        for(auto i : adj[st]){
            if(i.first == par) continue;
            if(a == -1){
                a = i.second;
                b = (i.second%2)?(i.second-1):(i.second+1);
            }
            else{
                c = i.second;
                d = (i.second%2)?(i.second-1):(i.second+1);
            }
        }

        vector<int> v = {a, b, c, d, b, a, d, c};
        for(auto i : v) path.push_back(i);
        return;
    }

    for(auto i : adj[st]){
        if(i.first == par) continue;
        path.push_back(i.second);
        dfs(i.first, st);
        path.push_back(i.second);
    }
}

variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V){

    adj.assign(N, {});
    for(int i = 0; i<M; i++){
        adj[U[i]].push_back({V[i], i});
    }
    if(adj[0].size() == 0) return (bool)0;
    if(adj[0].size() > 1){
        path.assign(0, 0);
        dfs(0, -1);
        return path;
    }

    int curr = adj[0][0].first;
    int prev = 0;
    while(adj[curr].size() <= 2){
        if(adj[curr].size() == 1) return (bool)0;
        if(adj[curr][1].first != prev){
            prev = curr;
            curr = adj[curr][1].first;
            continue;
        }
        prev = curr;
        curr = adj[curr][0].first;
    }

    path.assign(0, 0);
    dfs(0, -1);

    return path;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…