이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
// constexpr int MAXN = 1e5 + 5;
constexpr int MAXN = 1e3 + 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}
bool 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, prev_barca : " << u << " " << (char)(prev_barca + 'A') << '\n';
    if (v[u]) {
        res_barche = {1};
        return;
    }
    v[u] = 1;
    for (auto [x, b_u, b_v] : adj_barche[u]) {
        barche2.push_back({u, b_u, b_v});
        
        dfs_tre(x, b_v);
        if (res_barche.size()) return;
        
        barche.pop_back();
    }
    v[u] = 0;
}
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 ++) {
        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);
    if (N <= 400) return subtask_two(N, M, U, V);
}
컴파일 시 표준 에러 (stderr) 메시지
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:148:1: warning: control reaches end of non-void function [-Wreturn-type]
  148 | }
      | ^
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:45:58: warning: 'f' may be used uninitialized in this function [-Wmaybe-uninitialized]
   45 |     vector<int> res = {a, c, e, f, d, b, e, c, a, b, d, f};
      |                                                          ^
islands.cpp:45:58: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:45:58: warning: 'd' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:45:58: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:45:58: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:45: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... |