제출 #1079201

#제출 시각아이디문제언어결과실행 시간메모리
1079201NourWael수천개의 섬 (IOI22_islands)C++17
26 / 100
40 ms12760 KiB
#include "islands.h" #include <bits/stdc++.h> //#include "grader.cpp" using namespace std; int const mxN = 1e3+5; vector<pair<int,int>> adj[mxN], adj2[mxN]; int n,m, cnt[mxN][mxN]; bool vis[mxN], poss[mxN]; vector<int> from[mxN]; bool flag = 0; vector<int> st, fin; void solve( int i , int p) { int fi=-1,se=-1,th=-1,fo=-1, n1 = 0,n2 = 0; for(auto it:adj[i]) { if(it.first==p) continue; if(fi==-1) { fi = it.second; n1 = it.first; } else if(se==-1) { se = it.second; n2 = it.first; } } for(auto it:adj[n1]) { if(it.first==i) { if(th==-1) th = it.second; else fo = it.second; } } for(auto it:adj[n2]) { if(it.first==i) { if(fo==-1) fo = it.second; } } fin = {fi,th,se,fo,th,fi,fo,se}; } void dfs ( int i ) { for(auto it:adj[i]) { if(vis[it.first]) continue; vis[it.first] = 1; st.push_back(it.second); if(adj[it.first].size()>2) { flag = 1; solve(it.first,i); return; } dfs(it.first); } } variant<bool,vector<int>> find_journey( int N, int M,vector<int> U, vector<int> V) { n = N, m = M; for(int i=0; i<m; i++) { adj[U[i]].push_back({V[i],i}), adj2[V[i]].push_back({U[i],i}); cnt[U[i]][V[i]]++; } vector<int> v; if(adj[0].size()>1) { solve(0,-1); return fin; } else { vis[0] = 1; dfs(0); } if(flag) { vector<int> tot = st; for(auto it:fin) tot.push_back(it); reverse(st.begin(),st.end()); for(auto it:st) tot.push_back(it); return tot; } 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...