이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 1e5 + 5;
constexpr int MAXM = 2e5 + 5;
vector<array<int, 3>> adj_barche[MAXN]; // adj[U[i]] {nodo, barca, barca di ritorno} 
vector<array<int, 3>> adj_quattro[MAXN]; // adj[U[i]] {nodo, barca1, altra barca}
int v[MAXN];
vector<int> barche;
vector<array<int, 3>> barche2; // da che nodo, prima barca, seconda barca
vector<int> res_barche;
variant<bool, vector<int>> n_two(int N, int M, vector<int> U, vector<int> V) {
    vector<int> el_primo;
    vector<int> el_secondo;
    for (int i = 0; i < M; i ++) {
        if (U[i] == 0) el_primo.push_back(i);
        if (U[i] == 1) el_secondo.push_back(i);
    }
    if (el_primo.size() >= 2 && el_secondo.size() >= 1) {
        int a = el_primo[0];
        int b = el_secondo[0];
        int c = el_primo[1];
        vector<int> res = {a, b, c, a, b, c};
        return res;
    }
    return false;
}
variant<bool, vector<int>> subtask_two(int N, int M, vector<int> U, vector<int> V) {
    int a, b, c, d, e, f;
    for (int i = 0; i < M; i ++) {
        if (U[i] == 0 && V[i] == 1) a = i;
        if (U[i] == 1 && V[i] == 0) b = i;
        if (U[i] == 1 && V[i] == 2) c = i;
        if (U[i] == 2 && V[i] == 1) d = i;
        if (U[i] == 2 && V[i] == 0) e = i;
        if (U[i] == 0 && V[i] == 2) f = i;
    }
    vector<int> res = {a, c, e, f, d, b, e, c, a, b, d, f};
    return res;
}
void dfs_tre(int u, int prev_barca) {
    // cout << "u, prev_barca : " << u << " " << (char)(prev_barca + 'A') << '\n';
    if (adj_barche[u].size() >= 2 + (prev_barca != -1)) {
        // cout << "ce ne sono due !!" << '\n';
        vector<int> barche_prese;
        for (auto [x, b_u, b_v] : adj_barche[u]) {
            if (b_u == prev_barca) continue; // non succede mai tho
            barche_prese.push_back(b_u);
            barche_prese.push_back(b_v);
            if (barche_prese.size() == 4) break;
        }
        int c = barche_prese[0];
        int d = barche_prese[1];
        int e = barche_prese[2];
        int f = barche_prese[3];
        
        vector<int> nuovo = {c, d, e, f, d, c, f, e};
        vector<int> old_barche = barche;
        reverse(old_barche.begin(), old_barche.end());
        for (auto x : nuovo) barche.push_back(x);
        for (auto x : old_barche) barche.push_back(x);
        
        res_barche = barche;
        return;
    }
    for (auto [x, b_u, b_v] : adj_barche[u]) {
        if (b_u == prev_barca) continue; // non succede mai tho
        barche.push_back(b_u);
        // cout << "vado verso " << x << '\n';
        dfs_tre(x, b_v);
        if (res_barche.size()) return;
        barche.pop_back();
    }
}
variant<bool, vector<int>> subtask_tre(int N, int M, vector<int> U, vector<int> V) {
    for (int i = 0; i < M; i ++) {
        adj_barche[U[i]].push_back({V[i], i, i ^ 1});
    }
    dfs_tre(0, -1);
    if (!res_barche.size()) return false;
    return res_barche;
}
void dfs_four(int u) {
    // cout << "u -> " << u << '\n';
    if (v[u] == 2) return;
    if (v[u] == 1) {
        // tolgo l'ultimo u preso
        int primo_u = -1;
        for (int i = 0; i < barche2.size(); i ++) {
            if (barche2[i][0] == u) {
                primo_u = i;
                break;
            }
        }
        assert(primo_u != -1);
        primo_u ++;
        vector<int> ciclo;
        ciclo.push_back(barche2[primo_u][1]);
        for (int i = primo_u + 1; i < barche2.size(); i ++) {
            ciclo.push_back(barche2[i][1]);
        }
        ciclo.push_back(barche2[primo_u][2]);
        ciclo.push_back(barche2[primo_u][1]);
        for (int i = barche2.size() - 1; i > primo_u; i --) {
            ciclo.push_back(barche2[i][1]);
        }
        ciclo.push_back(barche2[primo_u][2]);
        res_barche.clear();
        for (int i = 0; i < primo_u; i ++) res_barche.push_back(barche2[i][1]);
        for (auto x : ciclo) res_barche.push_back(x);
        for (int i = primo_u - 1; i >= 0; i --) res_barche.push_back(barche2[i][1]);
        
        return;
    }
    v[u] = 1;
    for (auto [x, b_u, b_v] : adj_barche[u]) {
        barche2.push_back({x, b_u, b_v});
        
        dfs_four(x);
        if (res_barche.size()) return;
        
        barche2.pop_back();
    }
    v[u] = 2;
}
variant<bool, vector<int>> subtask_four(int N, int M, vector<int> U, vector<int> V) {
    fill(v, v + MAXN, 0);
    for (int i = 0; i < M; i += 2) {
        adj_barche[U[i]].push_back({V[i], i, i + 1});
    }
    dfs_four(0);
    if (!res_barche.size()) return false;
    return res_barche;
}
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
    if (N <= 2) return n_two(N, M, U, V);
    bool flag_subtask_tre = true;
    for (int i = 0; i < M; i += 2) {
        if (!(U[i] == V[i + 1] && V[i] == U[i + 1])) flag_subtask_tre = false;
    }
    if (flag_subtask_tre) return subtask_tre(N, M, U, V);
    bool flag_subtask_four = true;
    for (int i = 0; i < M; i += 2) {
        if (!(U[i] == U[i + 1] && V[i] == V[i + 1])) flag_subtask_four = false;
    }
    // if (flag_subtask_four) return subtask_four(N, M, U, V);
    return subtask_four(N, M, U, V);
    if (N <= 400) return subtask_two(N, M, U, V);
}
컴파일 시 표준 에러 (stderr) 메시지
islands.cpp: In function 'void dfs_four(int)':
islands.cpp:104:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |         for (int i = 0; i < barche2.size(); i ++) {
      |                         ~~^~~~~~~~~~~~~~~~
islands.cpp:115:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |         for (int i = primo_u + 1; i < barche2.size(); i ++) {
      |                                   ~~^~~~~~~~~~~~~~~~
islands.cpp: In function 'std::variant<bool, std::vector<int, std::allocator<int> > > find_journey(int, int, std::vector<int>, std::vector<int>)':
islands.cpp:168:10: warning: variable 'flag_subtask_four' set but not used [-Wunused-but-set-variable]
  168 |     bool flag_subtask_four = true;
      |          ^~~~~~~~~~~~~~~~~
islands.cpp: In function 'std::variant<bool, std::vector<int, std::allocator<int> > > subtask_two(int, int, std::vector<int>, std::vector<int>)':
islands.cpp:44:58: warning: 'f' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |     vector<int> res = {a, c, e, f, d, b, e, c, a, b, d, f};
      |                                                          ^
islands.cpp:44:58: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:44:58: warning: 'd' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:44:58: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:44:58: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:44:58: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |