제출 #1183598

#제출 시각아이디문제언어결과실행 시간메모리
1183598PagodePaiva수천개의 섬 (IOI22_islands)C++20
24 / 100
25 ms7864 KiB
#include "islands.h"
#include<bits/stdc++.h>
#include <variant>
#include <vector>

using namespace std;

// pega a dfstree. se eu tenho alguma backedge -> ok
// cc -> ruim, porque eu nunca vou conseguir subir para 0

const int N = 1010;
const int M = 200010;
vector <pair <int, int>> g[N];
int tin[N], tout[N];
int mark[N];
int tmm = 1;
pair <int, int> pai[N];
vector <int> res;

void dfs(int v, int p, int idx){
    pai[v] = {p, idx};
    tin[v] = tmm;
    tmm++;
    mark[v] = 1;
    for(auto [x, i] : g[v]){
        if(mark[x])
            continue;
        dfs(x, v, i);
    }
    tout[v] = tmm;
    tmm++;
}

void app(vector <int> v){
    for(auto x : v)
        res.push_back(x);
}

std::variant<bool, std::vector<int>> find_journey(
    int N, int m, std::vector<int> U, std::vector<int> V) {
    vector <pair <int, int>> arestas;
    for(int i = 0;i < m;i++){
        g[U[i]].push_back({V[i], i});
        arestas.push_back({U[i], V[i]});
    } 
    memset(mark, 0, sizeof mark);
    memset(tin, -1, sizeof tin);
    memset(tout, -1, sizeof tout);
    dfs(0, 0, M-1);
    vector <int> ans = {};
    for(int i = 0;i < arestas.size();i++){
        auto [x, y] = arestas[i];
        if(mark[x] == 0 or mark[y] == 0) continue;
        if(tin[y] <= tin[x] and tout[x] <= tout[y]){
            vector <int> path;
            int yy = y;
            while(yy != 0){
                path.push_back(pai[yy].second);
                yy = pai[yy].first;
            }
            reverse(path.begin(), path.end());
            app(path);
            vector <int> ciclo;
            ciclo.push_back(i);
            int xx = x;
            while(xx != y){
                ciclo.push_back(pai[xx].second);
                xx = pai[xx].first;
            }
            reverse(ciclo.begin(), ciclo.end());
            app(ciclo);
            for(auto x : ciclo){
                res.push_back(x^1);
            }
            reverse(ciclo.begin(), ciclo.end());
            app(ciclo);
            for(auto x : ciclo){
                res.push_back(x^1);
            }
            reverse(path.begin(), path.end());
            app(path);
            return res;
        }
    }
    return false;
}
#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...