# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
537544 | 2022-03-15T08:09:24 Z | jamezzz | Paths (RMI21_paths) | C++17 | 129 ms | 12024 KB |
#include <bits/stdc++.h> using namespace std; #define sf scanf #define pf printf #define fi first #define se second #define pb push_back typedef long long ll; typedef pair<int,int> ii; #define maxn 100005 int n,k,x[maxn],y[maxn],c[maxn],p[maxn]; ll d[maxn],ans[maxn]; vector<ii> AL[maxn]; void dfs(int u){ for(ii pr:AL[u]){ int i=pr.fi,v=pr.se; if(v==p[u])continue; p[v]=u; d[v]=d[u]+c[i]; dfs(v); } } int main(){ sf("%d%d",&n,&k); for(int i=0;i<n-1;++i){ sf("%d%d%d",&x[i],&y[i],&c[i]); AL[x[i]].pb({i,y[i]}); AL[y[i]].pb({i,x[i]}); } d[1]=0;p[1]=0;dfs(1); int mx=1; for(int i=1;i<=n;++i)if(d[i]>d[mx])mx=i; d[mx]=0;p[mx]=0;dfs(mx); for(int i=1;i<=n;++i){ ans[i]=d[i]; if(d[i]>d[mx])mx=i; } d[mx]=0;p[mx]=0;dfs(mx); for(int i=1;i<=n;++i){ ans[i]=max(ans[i],d[i]); pf("%lld\n",ans[i]); } } /* 11 3 1 2 5 2 3 3 2 6 5 3 4 4 3 5 2 1 7 6 7 8 4 7 9 5 1 10 1 10 11 1 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2644 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2644 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2644 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2644 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 79 ms | 10572 KB | Output is correct |
2 | Correct | 129 ms | 12024 KB | Output is correct |
3 | Correct | 77 ms | 10200 KB | Output is correct |
4 | Correct | 69 ms | 10500 KB | Output is correct |
5 | Correct | 76 ms | 11528 KB | Output is correct |
6 | Correct | 76 ms | 10572 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2644 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |