Submission #404338

#TimeUsernameProblemLanguageResultExecution timeMemory
404338AmineTrabelsiStations (IOI20_stations)C++14
69.87 / 100
998 ms776 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; const int Mx = 1010; int timer = 0; void dfs(int node,int par,vector<int> &labels,vector<vector<int>> &tr,bool parity){ if(!parity)labels[node] = timer++; else timer++; for(auto i:tr[node]){ if(i != par){ dfs(i,node,labels,tr,!parity); } } if(parity)labels[node] = timer++; else timer++; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { vector<int> labels(n); vector<vector<int>> tr(n+1,vector<int>(0)); for (int i = 0; i < n-1; i++) { tr[u[i]].push_back(v[i]); tr[v[i]].push_back(u[i]); } dfs(0,-1,labels,tr,0); for(auto &i:labels)i /=2; return labels; } int find_next_station(int s, int t, vector<int> c) { if ((int)c.size() == 1) return c.back(); if (c.front() > s){ // s in tin int l = s, r = c[(int)c.size() - 2]; if (l > t || r < t) return c.back(); int pos = lower_bound(c.begin(), c.end(), t) - c.begin(); return c[pos]; } // s is tout int l = c[1], r = s; if (l > t || r < t) return c.front(); int pos = upper_bound(c.begin(), c.end(), t) - c.begin() - 1; return c[pos]; }
#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...