Submission #373632

#TimeUsernameProblemLanguageResultExecution timeMemory
373632Jarif_RahmanStations (IOI20_stations)C++17
0 / 100
1089 ms1064 KiB
#include "stations.h" #include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; vector<vector<int>> v; vector<int> lb, sz; pair<int, int> div(int x){ return make_pair(x/1000, x%1000); } int in = 0; void dfs(int nd, int ss){ lb[nd] = 1000*in; in++; for(int x: v[nd]) if(x!=ss) dfs(x, nd); for(int x: v[nd]) if(x!=ss) sz[nd]+=sz[x]; lb[nd]+=sz[nd]; } vector<int> label(int n, int k, vector<int> aa, vector<int> bb){ v.assign(n, {}); lb.assign(n, -1); sz.assign(n, 1); for(int i = 0; i < n-1; i++){ v[aa[i]].pb(bb[i]); v[bb[i]].pb(aa[i]); } dfs(0, -1); return lb; } int find_next_station(int s, int t, vector<int> c){ sort(c.begin(), c.end()); auto [a, b] = div(s); auto [x, y] = div(t); if(x < a || x > a+b-1) return c.front(); if(c.size() == 1) return c.front(); if(a != 0) c.erase(c.begin()); for(int xx: c){ auto [aa, bb] = div(xx); if(x >= aa && x <= aa+bb-1) return xx; } 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...