Submission #1077923

#TimeUsernameProblemLanguageResultExecution timeMemory
1077923Faisal_SaqibThousands Islands (IOI22_islands)C++17
10 / 100
93 ms20404 KiB
#include <bits/stdc++.h> #include <variant> #include <vector> using namespace std; const int N=1e3+100; int n,m; vector<int> adj[N]; int color[N],parent[N]; map<pair<int,int>,int> helper; int cycle_start, cycle_end; bool dfs(int v) { color[v] = 1; for (int u : adj[v]) { if(u==parent[v])continue; if (color[u] == 0) { parent[u] = v; if (dfs(u)) return true; } else if (color[u] == 1) { if(u==0) { cycle_end = v; cycle_start = u; } return true; } } color[v] = 2; return false; } vector<int> find_cycle() { for(int i=0;i<n;i++) { color[i]=0; parent[i]=-1; } cycle_start = -1; for (int v = 0; v < n; v++) { if (color[v] == 0 && dfs(v)) break; } if (cycle_start == -1) { return {}; } else { vector<int> cycle; cycle.push_back(cycle_start); for (int v = cycle_end; v!=cycle_start; v = parent[v]) cycle.push_back(v); cycle.push_back(cycle_start); reverse(cycle.begin(), cycle.end()); return cycle; } } std::variant<bool, std::vector<int>> find_journey(int N, int M, std::vector<int> v1, std::vector<int> v2) { int n=N,m=M; map<pair<int,int>,vector<int>> cnt; for(int j=0;j<m;j++) cnt[{v1[j],v2[j]}].push_back(j); for(int i=1;i<n;i++) { for(int j=i+1;j<n;j++) { if(cnt[{0,i}].size()==0 or cnt[{0,j}].size()==0 or cnt[{i,j}].size()==0)continue; int edge01=cnt[{0,i}][0]; int edge10=cnt[{i,0}][0]; int edge02=cnt[{0,j}][0]; int edge20=cnt[{j,0}][0]; int edge12=cnt[{i,j}][0]; int edge21=cnt[{j,i}][0]; return vector<int>({edge01,edge12,edge20,edge02,edge21,edge10,edge20,edge12,edge01,edge10,edge21,edge02}); } } if(cnt[{0,1}].size()>=2 and cnt[{1,0}].size()>=1) { int f=cnt[{0,1}][0]; int s=cnt[{0,1}][1]; int th=cnt[{1,0}][0]; return vector<int>({f,th,s,f,th,s}); } 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...