Submission #632088

#TimeUsernameProblemLanguageResultExecution timeMemory
6320884123xr4323Thousands Islands (IOI22_islands)C++17
22.75 / 100
1081 ms530480 KiB
#include <bits/stdc++.h>
#define mp make_pair
#define all(a) a.begin(),a.end()
#define X first
#define Y second
using namespace std;
using pii = pair <long long, long long>;
constexpr int maxn = 2e5 + 10;
constexpr int mod = 1000002022;
constexpr long long inf = 1e17 + 10;
 
int n, m;
vector <pii> graph [maxn];
vector <int> start = {};
int ver = -1;
int ans[4];

inline void dfs (int v, int par = -1) {
    int sz = (int) graph[v].size ();
    if (par > -1) --sz;
    if (sz <= 1) {
        for (pii i : graph[v]) if ((i.Y ^ 1) != par) {
            start.push_back (i.Y);
            dfs (i.X, i.Y);
            return;
        }
        return;
    }
    ver = 0;
    ans[0] = graph[v][0].Y;
    ans[2] = graph[v][1].Y;
    if ((graph[v][0].Y ^ 1) == par) ans[0] = graph[v][2].Y;
    else if ((graph[v][1].Y ^ 1) == par) ans[2] = graph[v][2].Y;
    ans[1] = (ans[0] ^ 1);
    ans[3] = (ans[2] ^ 1);
}

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) {
        graph[U[i]].push_back (mp (V[i], i));
    }
    dfs (0);
    if (ver == -1) {
        return false;
    }
    vector <int> res = {};
    for (int i : start) res.push_back (i);
    res.push_back (ans[0]);
    res.push_back (ans[1]);
    res.push_back (ans[2]);
    res.push_back (ans[3]);
    res.push_back (ans[1]);
    res.push_back (ans[0]);
    res.push_back (ans[3]);
    res.push_back (ans[2]);
    reverse (all (start));
    for (int i : start) res.push_back (i);
    return res;
}
#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...