Submission #602026

#TimeUsernameProblemLanguageResultExecution timeMemory
602026FatihSolakStations (IOI20_stations)C++17
0 / 100
897 ms672 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; #define N 1000 vector<int> adj[N]; int tin[N]; int tout[N]; int dep[N]; int timer = 0; void dfs(int v,int par){ tin[v] = timer++; for(auto u:adj[v]){ if(u == par)continue; dep[u] = dep[v]+1; dfs(u,v); } tout[v] = timer-1; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { timer = 0; for(int i = 0;i<n;i++){ adj[i].clear(); } for(int i = 0;i<n-1;i++){ adj[u[i]].push_back(v[i]); adj[v[i]].push_back(u[i]); } dfs(0,-1); vector<int> labels(n); vector<pair<int,int>> ord; for (int i = 0; i < n; i++) { if(dep[i] & 1){ ord.push_back({tin[i],i}); } else{ ord.push_back({tout[i],i}); } } sort(ord.begin(),ord.end()); for(int i = 0;i<n;i++){ labels[ord[i].second] = i; } return labels; } int find_next_station(int s, int t, vector<int> c) { int sz = c.size(); sort(c.begin(),c.end()); for(auto u:c){ if(u == t) return u; } if(c[0] > s){ int last = s + 1; for(int i = 0;i<sz-1;i++){ if(last <= t && t <= c[i]){ return c[i]; } last = c[i] + 1; } return c[sz-1]; } else{ reverse(c.begin(),c.end()); int last = s - 1; for(int i = 0;i<sz-1;i++){ if(c[i] <= t && t <= last){ return c[i]; } last = c[i] - 1; } return c[sz-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...