Submission #1028874

#TimeUsernameProblemLanguageResultExecution timeMemory
1028874MardonbekhazratovThousands Islands (IOI22_islands)C++17
6.75 / 100
59 ms12536 KiB
#include "islands.h" #include <variant> #include <iostream> #include <vector> #include <algorithm> #include <tuple> #include <map> using namespace std; int n,m; vector<int>u,v; variant<bool,vector<int>>sub1(){ vector<int>c1,c2; for(int i=0;i<m;i++){ if(u[i]==0) c1.push_back(i); else c2.push_back(i); } if(c1.size()<2 || c2.size()<1) return false; return vector<int>({c1[0],c2[0],c1[1],c1[0],c2[0],c1[1]}); } vector<int>sub2(){ vector<vector<int>>a(3,vector<int>(3)); for(int i=0;i<m;i++){ if(u[i]<3 && v[i]<3) a[u[i]][v[i]]=i; } return vector<int>({a[0][1],a[1][0],a[0][2],a[2][1],a[0][1],a[1][0],a[2][1],a[0][2]}); } vector<vector<int>>adj; vector<int>vis,cf,cycle; bool found; void dfs(int x,int p){ if(found) return; vis[x]=1; cf[x]=p; for(int z:adj[x]){ if(z==p || vis[z]==2 || found) continue; if(z==0){ while(x!=0){ cycle.push_back(x); x=cf[x]; } cycle.push_back(0); found=true; return; } if(vis[z]==1) continue; dfs(z,x); } vis[x]=2; } variant<bool,vector<int>>sub3(){ adj.resize(n); for(int i=0;i<m;i++){ adj[u[i]].push_back(v[i]); } vis.assign(n,0); found=false; cf.resize(n); dfs(0,0); if(cycle.size()<3) return false; vector<int>ans; vector<map<int,int>>b(n); for(int i=0;i<m;i++) b[u[i]][v[i]]=i; reverse(cycle.begin(),cycle.end()); cycle.push_back(0); ans.push_back(b[0][cycle[1]]); for(int i=cycle.size()-1;i>1;i--) ans.push_back(b[cycle[i]][cycle[i-1]]); ans.push_back(b[0][cycle[1]]); for(int i=2;i<cycle.size();i++) ans.push_back(b[cycle[i]][cycle[i-1]]); // for(int x:cycle) cout<<x<<' '; return ans; } std::variant<bool, std::vector<int>> find_journey(int N, int M, std::vector<int> U, std::vector<int> V) { tie(n,m,u,v)=tie(N,M,U,V); if(n==2) return sub1(); return sub3(); }

Compilation message (stderr)

islands.cpp: In function 'std::variant<bool, std::vector<int, std::allocator<int> > > sub3()':
islands.cpp:76:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |     for(int i=2;i<cycle.size();i++) ans.push_back(b[cycle[i]][cycle[i-1]]);
      |                 ~^~~~~~~~~~~~~
#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...