Submission #1076628

#TimeUsernameProblemLanguageResultExecution timeMemory
1076628mindiyakStations (IOI20_stations)C++14
0 / 100
4 ms596 KiB
#include "stations.h" #include <vector> #include <queue> using namespace std; vector<vector<int>> paths(1001); vector<int> dist(1001,-1); void dfs(int pos,int len){ if(dist[pos] != -1)return; dist[pos] = 0; for(int i:paths[pos])dfs(i,len+1); } std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { std::vector<int> labels(n); paths = vector<vector<int>>(1001); dist = vector<int>(1001,-1); for(int i = 0;i<n-1;i++){ paths[u[i]].push_back(v[i]); paths[v[i]].push_back(u[i]); } dfs(0,0); int head = 0,len = 0; for (int i = 0; i < n; i++) { if(len<dist[i])head = i; len = max(len,dist[i]); } dist = vector<int>(1001,-1); dfs(head,0); for (int i = 0; i < n; i++) { labels[i] = dist[i]; } return labels; } int find_next_station(int s, int t, std::vector<int> c) { if(s>t)return c[0]; return c[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...