Submission #824256

#TimeUsernameProblemLanguageResultExecution timeMemory
824256LiudasThousands Islands (IOI22_islands)C++17
10 / 100
35 ms6416 KiB
#include "islands.h" #include <cassert> #include <cstdio> #include <variant> #include <vector> #include <algorithm> using namespace std; bool loop = false; void dfs(int node, vector<vector<pair<int, int>>> &tree, vector<bool> &vis){ if(vis[node]){ loop = true; return; } vis[node] = true; for(auto&[l, r] : tree[node]){ if(!r){ r = true; dfs(l, tree, vis); } } } variant<bool, vector<int>> find_journey(int N, int M, std::vector<int> U, std::vector<int> V) { if (N == 2){ if(count(U.begin(), U.end(), 0) >= 2 && count(U.begin(), U.end(), 1) >= 1){ vector<pair<int, int>> ans(M); for(int i = 0; i < M; i ++){ ans[i] = {U[i], i}; } sort(ans.begin(), ans.end()); vector<int> ret = {ans[0].second, ans.back().second, ans[1].second, ans[0].second, ans.back().second, ans[1].second}; return ret; } return false; } if(N * (N - 1) == M){ vector<vector<pair<int, int>>> tree(N); for(int i = 0; i < M; i ++){ tree[U[i]].push_back({V[i], i}); } for(int i = 0; i < N; i ++){ sort(tree[i].begin(), tree[i].end()); } vector<int> ret = {tree[0][0].second, tree[1][0].second, tree[0][1].second, tree[2][0].second, tree[1][0].second, tree[0][0].second, tree[2][0].second, tree[0][1].second}; return ret; } vector<vector<pair<int,int>>> tree(N); for(int i = 0; i < M; i ++){ tree[U[i]].push_back({V[i], 0}); } vector<bool> vis(N, 0); dfs(0, tree, vis); vector<int> arr(3, 0); if(loop){ //cout << 1 << endl; return arr; } else{ //cout << 2 << endl; return false; } return false; }
#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...