Submission #550647

#TimeUsernameProblemLanguageResultExecution timeMemory
550647krit3379Stations (IOI20_stations)C++17
100 / 100
814 ms5528 KiB
#include<bits/stdc++.h> using namespace std; #include"stations.h" #define N 100005 int st[N],en[N],cnt[N],sz; vector<int> g[N]; void dfs(int s,int f,int c){ st[s]=sz++; cnt[s]=c; for(auto x:g[s]){ if(x==f)continue; dfs(x,s,c+1); } en[s]=sz++; } vector<int> label(int n, int k, vector<int> u, vector<int> v){ int i,a,b,c=0; vector<int> vec; for(i=0;i<n;i++)g[i].clear(),sz=0; for(i=0;i<n-1;i++){ a=u[i],b=v[i]; g[a].push_back(b); g[b].push_back(a); } dfs(0,-1,1); map<int,int> mp; for(i=0;i<n;i++)mp[cnt[i]%2?st[i]:en[i]]; for(auto &[x,y]:mp)y=c++; for(i=0;i<n;i++)vec.push_back(mp[cnt[i]%2?st[i]:en[i]]); return vec; } int find_next_station(int s, int t,vector<int> c){ if(c[0]>s){ //s->st if(t<s)return c.back(); for(auto x:c)if(t<=x)return x; return c.back(); } else{ //s->en if(t>s)return c[0]; for(int i=c.size()-1;i>=0;i--)if(t>=c[i])return c[i]; return c[0]; } }
#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...