Submission #1067185

#TimeUsernameProblemLanguageResultExecution timeMemory
1067185j_vdd16Thousands Islands (IOI22_islands)C++17
0 / 100
1135 ms1770364 KiB
#include "islands.h" #include <variant> #include <algorithm> #include <bitset> #include <cstdint> #include <cstring> #include <iostream> #include <limits.h> #include <math.h> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> //#define int long long #define loop(X, N) for(int X = 0; X < (N); X++) #define all(V) V.begin(), V.end() #define rall(V) V.rbegin(), V.rend() using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<vector<ii>> vvii; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef uint64_t u64; typedef int64_t i64; int n, m; vvii adj; vb vis; vi depths; bool success = false; int counter = 0; vii inOut; int dfs(int node, int d, int parent) { if (node == parent) return 0; if (vis[node]) { return 1; } vis[node] = true; depths[node] = d; inOut[node].first = counter++; int count = 0; for (auto [child, idx] : adj[node]) { if (child == parent) continue; int res = dfs(child, d + 1, node); count += res; } if (count >= 2) success = true; inOut[node].second = counter++; return 1; } bool isAncestor(int a, int b) { return inOut[a].first <= inOut[b].first && inOut[b].first <= inOut[a].second; } vi parents; vi succesPath; vi path; vi dfs2(int node, int parent, int edgeIdx) { if (vis[node]) { return { edgeIdx }; } parents[node] = parent; vis[node] = true; int count = 0; vvi validPaths; for (auto [child, idx] : adj[node]) { if (child == parent) continue; path.push_back(idx); vi res = dfs2(child, node, idx); path.pop_back(); if (res.size() && count < 2) { count++; validPaths.push_back(res); } } if (count >= 2 && !success) { success = true; succesPath = path; for (int idx : validPaths[0]) { succesPath.push_back(idx); } for (int i = validPaths[0].size() - 1; i >= 0; i--) { succesPath.push_back(validPaths[0][i] ^ 1); } for (int idx : validPaths[1]) { succesPath.push_back(idx); } for (int i = validPaths[1].size() - 1; i >= 0; i--) { succesPath.push_back(validPaths[0][i] ^ 1); } for (int i = validPaths[0].size() - 1; i >= 0; i--) { succesPath.push_back(validPaths[0][i] ^ 1); } for (int idx : validPaths[0]) { succesPath.push_back(idx); } for (int i = validPaths[1].size() - 1; i >= 0; i--) { succesPath.push_back(validPaths[0][i] ^ 1); } for (int idx : validPaths[1]) { succesPath.push_back(idx); } for (int i = path.size() - 1; i >= 0; i++) { succesPath.push_back(succesPath[i] ^ 1); } } if (validPaths.size() == 0) { return { edgeIdx }; } validPaths[0].push_back(edgeIdx); return validPaths[0]; } std::variant<bool, std::vector<int>> find_journey(int N, int M, vi U, vi V) { n = N; m = M; adj = vvii(n); loop(i, m) { adj[U[i]].push_back({V[i], i}); } // if (n >= 3) { // int n1 = adj[0][0].first; // int n2 = adj[0][1].first; // return vi{adj[0][0].second, adj[n1][0].second, adj[0][1].second, adj[n2][0].second, adj[n1][0].second, adj[0][0].second, adj[n2][0].second, adj[0][1].second }; // } // return false; depths = vi(n); counter = 0; inOut = vii(n); vis = vb(n); success = false; parents = vi(n); dfs2(0, -1, -1); // vis = vb(n); // marked = vi(n); // dfs2(0); if (success) { return succesPath; } return false; // return false; // return success; }
#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...