Submission #602373

#TimeUsernameProblemLanguageResultExecution timeMemory
602373rrrr10000Keys (IOI21_keys)C++17
67 / 100
3063 ms88960 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> P; typedef tuple<ll,ll,ll> PP; typedef vector<ll> vi; typedef vector<vi> vvi; typedef vector<bool> vb; typedef vector<P> vp; typedef vector<vp> vvp; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++) #define fi first #define se second #define pb emplace_back #define all(a) a.begin(),a.end() template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;} template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;} template<class T> void out(T a){cout<<a<<endl;} template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;} vector<int> find_reachable(vector<int> r, vector<int> u, vector<int> v, vector<int> c) { ll n=r.size(),m=u.size(); vi ord(n);rep(i,n)ord[i]=i;random_shuffle(all(ord)); vi seen1(n,-1),seen2(n,-1); vb done(n,false),ok_c(n,false); vvp g(n); vvi edges(n); rep(i,m){ g[u[i]].pb(v[i],c[i]); g[v[i]].pb(u[i],c[i]); } vi p(n,n+1); ll cnt_seen1=-1,cnt_seen2=-1; for(ll s:ord)if(!done[s]){ // rep(i,n)assert(edges[i].size()==0); vi tmp_c,tmp; cnt_seen1++; function<bool(ll)> dfs1=[&](ll i){ if(done[i])return false; tmp.pb(i); seen1[i]=cnt_seen1; if(!ok_c[r[i]]){ tmp_c.pb(r[i]); ok_c[r[i]]=true; for(ll x:edges[r[i]])if(seen1[x]!=cnt_seen1){ if(!dfs1(x))return false; } } for(auto x:g[i])if(seen1[x.fi]!=cnt_seen1){ if(ok_c[x.se]){ if(!dfs1(x.fi))return false; } else{ tmp_c.pb(x.se); edges[x.se].pb(x.fi); } } return true; }; bool res=dfs1(s); for(ll x:tmp_c){ edges[x].clear(); ok_c[x]=false; }tmp_c.clear(); if(res){ // out(s);outv(tmp); for(ll x:tmp)p[x]=tmp.size(); } done[s]=true; } ll mi=n+1; for(ll x:p)chmin(mi,x); vector<int> ans(n); rep(i,n)if(p[i]==mi)ans[i]=1; return ans; }

Compilation message (stderr)

keys.cpp: In function 'std::vector<int> find_reachable(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
keys.cpp:34:18: warning: unused variable 'cnt_seen2' [-Wunused-variable]
   34 |  ll cnt_seen1=-1,cnt_seen2=-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...