Submission #1054807

#TimeUsernameProblemLanguageResultExecution timeMemory
1054807LittleOrangeStations (IOI20_stations)C++17
100 / 100
563 ms1272 KiB
#include "stations.h" #include <vector> #include<bits/stdc++.h> using namespace std; using ll = int; std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { vector<ll> labels(n); iota(labels.begin(),labels.end(),0); vector<vector<ll>> con(n); for(ll i = 0;i<n-1;i++){ con[u[i]].push_back(v[i]); con[v[i]].push_back(u[i]); } fill(labels.begin(),labels.end(),-1); /*for(ll i = 0;i<n;i++){ if (con[i].size()==1&&labels[i]==-1){ ll cur = i; ll it = 0; while(cur!=-1){ labels[cur] = it++; ll nxt = -1; for(ll j : con[cur]) if (labels[j]==-1) nxt = j; cur = nxt; } } }*/ /*ll rt = 0; for(ll i = 0;i<n;i++) if(con[i].size()>2) rt = i; labels[rt] = 0; ll gp = 0; for(ll i : con[rt]){ ll g = (++gp)*1000; ll x = i; while(x!=-1){ labels[x] = g++; ll nw = -1; for(ll j : con[x]){ if(labels[j]==-1){ nw = j; } } x = nw; } }*/ vector<vector<ll>> ch(n); vector<ll> sz(n,1); { function<void(ll,ll)> dfs; dfs = [&](ll i, ll p){ for(ll j : con[i]) if(j!=p){ ch[i].push_back(j); dfs(j,i); sz[i]+=sz[j]; } }; dfs(0,-1); } { function<void(ll,ll,ll)> dfs; dfs = [&](ll i, ll it,ll pos){ if (pos){ labels[i] = it+sz[i]-1; }else{ labels[i] = it++; } for(ll j : ch[i]){ dfs(j, it, pos^1); it += sz[j]; } }; dfs(0,0,0); } //for(ll i = 0;i<n;i++) cerr << labels[i] << " \n"[i+1==n]; return labels; } int find_next_station(int s, int t, std::vector<int> C) { deque<ll> c(C.begin(),C.end()); //cerr << s << " " << t << " :"; //for(ll i : c) cerr << " " << i; //cerr << "\n"; /*s++;t++; ll lgs = __lg(s), lgt = __lg(t); if (lgs<lgt){ ll x = t>>(lgt-lgs); if (s==x){ return (t>>(lgt-lgs-1))-1; } } return (s>>1)-1;*/ /*if (t>s) return s+1; else return s-1;*/ /*ll gs = s/1000; ll gt = t/1000; if (gs==0){ for(ll i : c){ if (i/1000==gt) return i; } }else if(gs==gt){ if(s>t){ for(ll i : c){ if (i<s) return i; } }else{ for(ll i : c){ if (i>s) return i; } } }else{ for(ll i : c){ if (i<s) return i; } }*/ sort(c.begin(),c.end()); if(s==0){ for(ll i : c) if(i>=t) return i; }else{ if (s<c[0]){ ll pa = c.back();c.pop_back(); if (t<s||c.empty()||t>c.back()) return pa; for(ll i : c) if(i>=t) return i; }else{ ll pa = c.front();c.pop_front(); if (t>s||c.empty()||t<c.front()) return pa; reverse(c.begin(),c.end()); for(ll i : c) if(i<=t) return i; } } return -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...