# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
419143 | 2021-06-06T13:27:44 Z | NintsiChkhaidze | Stations (IOI20_stations) | C++14 | 914 ms | 752 KB |
#include "stations.h" #include <bits/stdc++.h> //#include <iostream> //#include <vector> #define pb push_back using namespace std; vector <int> vec[1005]; int dp[1005],d[23][1005]; void dfs(int x,int p){ d[0][x] = p; dp[x] = dp[p] + 1; for (int j=0;j<vec[x].size();j++){ int to = vec[x][j]; if (to == p) continue; dfs(to,x); } } vector<int> label(int n, int k, vector<int> u, vector<int> v) { vector<int> labels; for (int i=0;i<1001;i++){ vec[i].clear(); dp[i] = 0; } for (int i=0;i<u.size();i++){ vec[u[i]].pb(v[i]); vec[v[i]].pb(u[i]); } dfs(0,0); for (int i=0;i<n;i++) for (int j = 1; j <= 18; j++) d[j][i] = d[j - 1][d[j - 1][i]]; for (int i=0;i<n;i++) labels.pb(i); return labels; } int lca(int x,int y){ for (int j = 18; j>= 0;j--) if (dp[d[j][x]] >= dp[y]) x = d[j][x]; if (x == y) return x; for (int j = 18; j>=0;j--) if (d[j][x] != d[j][y]) x = d[j][x],y = d[j][y]; return d[0][x]; } int dis(int x,int y){ if (dp[x] < dp[y]) swap(x,y); int c = lca(x,y); //cout<<x<<" ^^ "<<y<<" lca = "<<c<<endl; return dp[x] +dp[y] - 2*dp[c]; } int find_next_station(int s, int t, vector<int> c) { int D = dis(s,t),ans=-1; for (int i=0;i<c.size();i++){ int DD = dis(c[i],t); // cout<<"DD == "<<DD<<" "<<c[i]<<" ^ "<<t<<endl; if (DD < D) ans = c[i]; } //cout<<"ans = "<<ans<<endl; return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 616 ms | 752 KB | Wrong query response. |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 576 ms | 628 KB | Wrong query response. |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 639 ms | 656 KB | Wrong query response. |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 914 ms | 520 KB | Wrong query response. |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 663 ms | 744 KB | Wrong query response. |
2 | Halted | 0 ms | 0 KB | - |