Submission #767258

#TimeUsernameProblemLanguageResultExecution timeMemory
767258t6twotwoThousands Islands (IOI22_islands)C++17
31 / 100
30 ms5272 KiB
#include "islands.h"
#include <bits/stdc++.h>
using namespace std;
variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) {
    if (N == 2) {
        vector<int> a, b;
        for (int i = 0; i < M; i++) {
            if (U[i] == 0) {
                a.push_back(i);
            } else {
                b.push_back(i);
            }
        }
        if (a.size() >= 2 && b.size() >= 1) {
            return vector{a[0], b[0], a[1], a[0], b[0], a[1]};
        } else {
            return false;
        }
    }
    bool subtask3 = 0;
    bool subtask4 = 0;
    if (M % 2 == 0) {
        subtask3 = 1;
        subtask4 = 1;
        for (int i = 0; i < M; i += 2) {
            if (U[i] != V[i + 1] || V[i] != U[i + 1]) {
                subtask3 = 0;
            }
            if (U[i] != U[i + 1] || V[i] != V[i + 1]) {
                subtask4 = 0;
            }
        }
    }
    if (subtask3) {
        vector<vector<pair<int, int>>> adj(N);
        for (int i = 0; i < M; i++) {
            adj[U[i]].emplace_back(V[i], i);
        }
        vector<int> ans;
        int x = 0, p = -1;
        while (1) {
            vector<array<int, 2>> f;
            for (auto [y, z] : adj[x]) {
                if (y != p) {
                    f.push_back({y, z});
                }
            }
            if (f.empty()) {
                return false;
            }
            if (f.size() == 1) {
                ans.push_back(f[0][1]);
                p = x;
                x = f[0][0];
                continue;
            }
            auto v = vector(ans.rbegin(), ans.rend());
            vector<int> s(M);
            ans.push_back(f[0][1]);
            ans.push_back(f[0][1] ^ 1);
            ans.push_back(f[1][1]);
            ans.push_back(f[1][1] ^ 1);
            ans.push_back(f[0][1] ^ 1);
            ans.push_back(f[0][1]);
            ans.push_back(f[1][1] ^ 1);
            ans.push_back(f[1][1]);
            ans.insert(ans.end(), v.begin(), v.end());
            return ans;
        }
    }
    int s[3][3];
    for (int i = 0; i < M; i++) {
        if (U[i] < 3 && V[i] < 3) {
            s[U[i]][V[i]] = i;
        }
    }
    return vector{s[0][1], s[1][2], s[2][0], s[0][2], s[2][1], s[1][0], s[2][0], s[1][2], s[0][1], s[1][0], s[2][1], s[0][2]};
}

Compilation message (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:21:10: warning: variable 'subtask4' set but not used [-Wunused-but-set-variable]
   21 |     bool subtask4 = 0;
      |          ^~~~~~~~
#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...