Submission #967481

#TimeUsernameProblemLanguageResultExecution timeMemory
967481WendidIask0303Stations (IOI20_stations)C++17
100 / 100
592 ms1512 KiB
#include "stations.h" #include <vector> using namespace std; vector<int> adj[1005]; vector<int> a; bool vis[1001]; int timer = 0; void dfs(int u, int d){ if (d == 0){ a[u] = timer; timer++; } vis[u] = true; for(auto v:adj[u]){ if (vis[v]) continue; dfs(v, d^1); } if (d == 1){ a[u] = timer; timer++; } } vector<int> label(int n, int k, vector<int> u, vector<int> v){ timer = 0; a.clear(); a.resize(n); for(int i=0;i<n;i++){ adj[i].clear(); vis[i] = false; } for(int i=0;i<n-1;i++){ adj[u[i]].push_back(v[i]); adj[v[i]].push_back(u[i]); } dfs(0,0); return a; } int find_next_station(int s, int t, vector<int> c) { if (c[c.size()-1] < s){ int ans = c[0]; for(auto x : c){ if(min(s, x) <= t && t <= max(s, x))ans = x; }return ans; } else { for (auto x : c)if(min(s, x) <= t && t <= max(s, x))return x; return c[c.size()-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...