제출 #736419

#제출 시각아이디문제언어결과실행 시간메모리
736419jk410수천개의 섬 (IOI22_islands)C++17
24 / 100
45 ms8268 KiB
#include "islands.h" #include <bits/stdc++.h> using namespace std; int n; int edge[1000][1000]; int visited[1000]; int par[1000]; pair<int,int> dfs(int v) { visited[v] = 1; for (int i = 0; i < n; i++) { if (edge[v][i] == -1 || visited[i] == 2) continue; if (visited[i] == 1) return { v,i }; par[i] = v; pair<int,int> tmp = dfs(i); if (tmp.first != -1) return tmp; } visited[v] = 2; return { -1,-1 }; } variant<bool, vector<int>> find_journey(int _n, int m, vector<int> u, vector<int> v) { n = _n; memset(edge, -1, sizeof(edge)); for (int i = 0; i < m; i += 2) edge[u[i]][v[i]] = i; pair<int,int> x = dfs(0); if (x.first == -1) return false; vector<int> cyc; cyc.push_back(x.second); for (int i = x.first;; i = par[i]) { cyc.push_back(i); if (i == x.second) break; } vector<int> p; for (int i = x.second;; i = par[i]) { p.push_back(i); if (!i) break; } vector<int> ret; for (int i = (int)p.size() - 1; i; i--) ret.push_back(edge[p[i]][p[i - 1]]); for (int i = (int)cyc.size() - 1; i; i--) ret.push_back(edge[cyc[i]][cyc[i - 1]]); for (int i = (int)cyc.size() - 1; i; i--) ret.push_back(edge[cyc[i]][cyc[i - 1]] + 1); for (int i = 1; i < (int)cyc.size(); i++) ret.push_back(edge[cyc[i]][cyc[i - 1]]); for (int i = 1; i < (int)cyc.size(); i++) ret.push_back(edge[cyc[i]][cyc[i - 1]] + 1); for (int i = 1; i < (int)p.size(); i++) ret.push_back(edge[p[i]][p[i - 1]]); return ret; }
#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...