제출 #830759

#제출 시각아이디문제언어결과실행 시간메모리
830759FatihSolak수천개의 섬 (IOI22_islands)C++17
8.40 / 100
187 ms30560 KiB
#include "islands.h" #include <bits/stdc++.h> #define N 100005 using namespace std; vector<pair<int,pair<int,int>>> adj[N]; map<int,vector<int>> mp[N]; int par[N]; int par2[N]; int vis[N]; vector<int> ans = {}; bool ok = 0; void dfs2(int v,int pr){ vis[v] = 1; vector<pair<int,pair<int,int>>> tmp; for(auto u:adj[v]){ if(ok) return; if(vis[u.first] == 2){ continue; } if(vis[u.first] == 1){ if(ok) return; ok = 1; int now = u.first; while(now != 0){ ans.push_back(par[now]); now = par2[now]; } reverse(ans.begin(),ans.end()); vector<int> v1 = {},v2 = {}; now = v; int cnt = 0; int sz = 1; while(now != u.first){ assert(cnt++ <= 1000); v1.push_back(par[now]); v2.push_back(par[now] + 1); sz++; // cout << now << endl; now = par2[now]; } reverse(v1.begin(),v1.end()); reverse(v2.begin(),v2.end()); v1.push_back(u.second.first); v2.push_back(u.second.first + 1); for(int i = 0;i<sz;i++){ for(int j = sz-i;j<sz;j++){ ans.push_back(v1[j]); } for(int j = 0;j<sz-i;j++){ ans.push_back(v1[j]); } for(int j = sz-i;j<sz;j++){ ans.push_back(v2[j]); } for(int j = 0;j<sz-i;j++){ ans.push_back(v2[j]); } } now = u.first; while(now != 0){ ans.push_back(par[now]); now = par2[now]; } return; } par[u.first] = u.second.first; par2[u.first] = v; dfs2(u.first,u.second.first); } vis[v] = 2; } variant<bool, vector<int>> find_journey(int n, int m, vector<int> U, vector<int> V){ for(int i = 0;i<m;i+=2){ adj[U[i]].push_back({V[i],{i,i+1}}); // cout << U[i] << ' ' << V[i] << endl; } dfs2(0,-1); if(!ok) return false; return ans; }
#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...