Submission #1059624

#TimeUsernameProblemLanguageResultExecution timeMemory
1059624shiomusubi496Thousands Islands (IOI22_islands)C++17
11.90 / 100
27 ms7636 KiB
#include "islands.h"

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i)

#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)

using namespace std;

using ll = long long;

template<class T, class U> bool chmin(T& a, const U& b) { return a > b ? a = b, true : false; }
template<class T, class U> bool chmax(T& a, const U& b) { return a < b ? a = b, true : false; }

struct edge {
    int to, idx;
};

using Graph = vector<vector<edge>>;

std::variant<bool, std::vector<int>> find_journey(int N, int M, std::vector<int> U, std::vector<int> V) {
    Graph G(N);
    rep (i, M) G[U[i]].push_back({V[i], i});
    vector<bool> seen(N, false), used(N, false);
    vector<bool> cycle1(N, false);
    vector<int> ans;
    int s = -1;
    bool flag = false;
    auto dfs = [&](auto&& self, int v) -> void {
        seen[v] = used[v] = true;
        for (auto e : G[v]) {
            if (used[e.to]) {
                if (s == -1) {
                    s = e.to;
                    cycle1[v] = true;
                    break;
                }
                else {
                    flag = true;
                    break;
                }
            }
            if (cycle1[e.to]) {
                flag = true;
                break;
            }
            if (seen[e.to]) continue;
            self(self, e.to);
            if (flag) break;
            if (s >= 0) {
                cycle1[v] = true;
                if (s != v) break;
                s = -2;
            }
        }
        used[v] = false;
    };
    dfs(dfs, 0);
    return flag;
}
#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...