Submission #1058360

#TimeUsernameProblemLanguageResultExecution timeMemory
1058360dozerThousands Islands (IOI22_islands)C++17
22.75 / 100
21 ms21464 KiB
#include "islands.h" #include <bits/stdc++.h> using namespace std; #define sp " " #define endl "\n" #define pii pair<int, int> #define st first #define nd second #define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #define fastio() cin.tie(0), ios_base::sync_with_stdio(0) #define pb push_back #define LL node * 2 #define RR node * 2 + 1 #define ll long long #define MAXN 300005 const int modulo = 1e9 + 7; const ll INF = 2e18 + 7; vector<pii> in[MAXN], out[MAXN]; int nxt(int a){ if (a % 2 == 0) return a + 1; return a - 1; } int dfs(int node, int par, deque<int> &ans){ vector<pii> go; for (auto i : out[node]){ if (i.st != par) go.pb(i); } if (go.size() >= 2){ int a = go[0].nd, b = go[1].nd; ans = {a, nxt(a), b, nxt(b), nxt(a), a, nxt(b), b}; return 1; } if (go.empty()) return 0; int to = go.front().st; int res = dfs(to, node, ans); if (res == 0) return 0; ans.push_front(go.front().nd); ans.push_back(go.front().nd); return 1; } variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) { for (int i = 0; i < M; i++){ in[V[i]].pb({U[i], i}); out[U[i]].pb({V[i], i}); } deque<int> a; int res = dfs(0, -1, a); if (res == 0) return false; vector<int> b; for (auto i : a) b.pb(i); return b; } /* int main() { fileio(); int N, M; assert(2 == scanf("%d %d", &N, &M)); std::vector<int> U(M), V(M); for (int i = 0; i < M; ++i) { assert(2 == scanf("%d %d", &U[i], &V[i])); } std::variant<bool, std::vector<int>> result = find_journey(N, M, U, V); if (result.index() == 0) { printf("0\n"); if (std::get<bool>(result)) { printf("1\n"); } else { printf("0\n"); } } else { printf("1\n"); std::vector<int> &canoes = std::get<std::vector<int>>(result); printf("%d\n", static_cast<int>(canoes.size())); for (int i = 0; i < static_cast<int>(canoes.size()); ++i) { if (i > 0) { printf(" "); } printf("%d", canoes[i]); } printf("\n"); } return 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...