Submission #632057

#TimeUsernameProblemLanguageResultExecution timeMemory
632057TimDeeThousands Islands (IOI22_islands)C++17
17.35 / 100
39 ms9420 KiB
#include "islands.h" #include <bits/stdc++.h> using namespace std; int n,m; vector<int> u,v; vector<int> vis(1e5+3,0); vector<int> par(1e5+3,-1); vector<vector<int>> adj(1e5+3,vector<int>(0)); variant<bool, std::vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) { n=N,m=M,u=U,v=V; if (n==2) { vector<int> fv,sv; for (int x=0; x<m; ++x) if (u[x]==0) fv.push_back(x); else sv.push_back(x); int f=fv.size(), s=sv.size(); if (f>=2 && s) { vector<int> r={fv[0],sv[0],fv[1],fv[0],sv[0],fv[1]};; return r; } else return false; } if (n<=400 && m==n*(n-1)) { int a,b,c,d; for (int i=0; i<m; ++i) { if (u[i]==0 && v[i]==1) a=i; if (u[i]==0 && v[i]==2) b=i; if (u[i]==1 && v[i]==0) c=i; if (u[i]==2 && v[i]==0) d=i; } vector<int> r = {a,c,b,d,c,a,d,b}; return r; } int _p3=1, _p4=1; for (int i=0; i<m; i+=2) { _p3&=((u[i]==v[i+1])&&(v[i]==u[i+1])); _p4&=((u[i]==u[i+1])&&(v[i]==v[i+1])); } if (_p3) { vector<int> deg(1e5+3,0); for (int i=0; i<m; i+=2) { deg[u[i]]++; deg[v[i]]++; adj[u[i]].push_back(v[i]); adj[v[i]].push_back(u[i]); } int mx=0; for (auto x:deg) mx=max(mx,x); if (mx<3) return false; if (deg[0]>=3) { int a=-1,b=-1,c=-1,d=-1; int f=-1,s=-1; for (auto x:adj[0]) { if (f==-1) f=x; else {s=x; break;} } for (int i=0; i<m; ++i) { if (u[i]==0 && v[i]==f) a=i; if (u[i]==0 && v[i]==s) b=i; if (u[i]==f && v[i]==0) c=i; if (u[i]==s && v[i]==0) d=i; } vector<int> r = {a,c,b,d,c,a,d,b}; return r; } vis[0]=1; queue<int> q; q.push(0); while (!q.empty()) { int x=q.front(); q.pop(); if (deg[x]>=3) { vector<int> r; int a,b,c,d; vector<int> path; int p=x; while (p!=0) { p=par[p]; path.push_back(p); } for (int i=path.size()-1; i>=0; --i) r.push_back(path[i]); return r; } for (auto y:adj[x]) { if (!vis[y]) { q.push(y); vis[y]=1; par[y]=x; } } } return false; } }

Compilation message (stderr)

islands.cpp: In function 'std::variant<bool, std::vector<int, std::allocator<int> > > find_journey(int, int, std::vector<int>, std::vector<int>)':
islands.cpp:84:13: warning: unused variable 'a' [-Wunused-variable]
   84 |         int a,b,c,d;
      |             ^
islands.cpp:84:15: warning: unused variable 'b' [-Wunused-variable]
   84 |         int a,b,c,d;
      |               ^
islands.cpp:84:17: warning: unused variable 'c' [-Wunused-variable]
   84 |         int a,b,c,d;
      |                 ^
islands.cpp:84:19: warning: unused variable 'd' [-Wunused-variable]
   84 |         int a,b,c,d;
      |                   ^
islands.cpp:108:1: warning: control reaches end of non-void function [-Wreturn-type]
  108 | }
      | ^
islands.cpp:35:37: warning: 'd' may be used uninitialized in this function [-Wmaybe-uninitialized]
   35 |     vector<int> r = {a,c,b,d,c,a,d,b};
      |                                     ^
islands.cpp:35:37: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:35:37: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:35:37: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
#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...