제출 #652869

#제출 시각아이디문제언어결과실행 시간메모리
652869Lobo수천개의 섬 (IOI22_islands)C++17
0 / 100
108 ms39240 KiB
#include "islands.h"
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
#define mp make_pair
#define all(x) x.begin(),x.end()

const int maxn = 2e5+10;
int n, m, tin[maxn], low[maxn], mark[maxn], iscyc[maxn], can0[maxn], timer;
int Ug[maxn], Vg[maxn];
vector<int> g[maxn], gt[maxn];
vector<pair<int,int>> gid[maxn];
map<int,vector<int>> boats[maxn];
vector<int> cur, final;
void dfs(int u) {
    mark[u] = 1;
    if(final.size()) return;
    for(auto V : gid[u]) if(V.sc%2 == 0) {
        if(final.size()) return;
        int v = V.fr;
        if(mark[v]) {
            final = cur;
            vector<int> cyc;
            cyc.pb(V.sc);
            while(final.size() && Vg[final.back()] != v) {
                cyc.pb(final.back());
                final.pop_back();
            }

            int aux = final.size()-1;

            reverse(all(cyc));
            for(auto x : cyc) final.pb(x);
            for(auto x : cyc) final.pb(x+1);
            reverse(all(cyc));
            for(auto x : cyc) final.pb(x);
            for(auto x : cyc) final.pb(x+1);

            for(int i = aux; i >= 0; i--) {
                final.pb(i);
            }
            return;
        }
        cur.pb(V.sc);
        dfs(v);
        cur.pop_back();
    }
}

void dfs0(int u) {
    can0[u] = 1;
    for(auto v : g[u]) {
        if(can0[v] == 0) dfs0(v);
    }
}

variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
    n = N;
    m = M;
    for(int i = 0; i < m; i++) {
        Ug[i] = U[i];
        Vg[i] = V[i];
        g[U[i]].pb(V[i]);
        gid[U[i]].pb(mp(V[i],i));
        gt[V[i]].pb(U[i]);
        boats[U[i]][V[i]].pb(i);
    }

    dfs(0);
    dfs0(0);

    if(final.size()) {
        return final;
    }
    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...