# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
537539 | 2022-03-15T07:59:20 Z | jamezzz | Paths (RMI21_paths) | C++17 | 600 ms | 9036 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]; int use[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]; if(!use[i])d[v]+=c[i]; dfs(v); } } bool dfs2(int u,int t){ if(u==t)return true; for(ii pr:AL[u]){ int i=pr.fi,v=pr.se; if(v==p[u])continue; if(dfs2(v,t)){ use[i]=1; return true; } } return false; } 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]}); } for(int i=1;i<=n;++i){ memset(use,0,sizeof use); ll ans=0; for(int j=0;j<k;++j){ p[i]=0;d[i]=0;dfs(i); int mx=i; for(int l=1;l<=n;++l){ if(d[l]>d[mx])mx=l; } ans+=d[mx]; dfs2(i,mx); } pf("%lld\n",ans); } } /* 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3044 KB | Output is correct |
2 | Correct | 2 ms | 3048 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3044 KB | Output is correct |
2 | Correct | 2 ms | 3048 KB | Output is correct |
3 | Correct | 18 ms | 3052 KB | Output is correct |
4 | Correct | 13 ms | 3028 KB | Output is correct |
5 | Correct | 14 ms | 3176 KB | Output is correct |
6 | Correct | 11 ms | 3088 KB | Output is correct |
7 | Correct | 12 ms | 3028 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3044 KB | Output is correct |
2 | Correct | 2 ms | 3048 KB | Output is correct |
3 | Correct | 18 ms | 3052 KB | Output is correct |
4 | Correct | 13 ms | 3028 KB | Output is correct |
5 | Correct | 14 ms | 3176 KB | Output is correct |
6 | Correct | 11 ms | 3088 KB | Output is correct |
7 | Correct | 12 ms | 3028 KB | Output is correct |
8 | Execution timed out | 1081 ms | 3112 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3044 KB | Output is correct |
2 | Correct | 2 ms | 3048 KB | Output is correct |
3 | Correct | 18 ms | 3052 KB | Output is correct |
4 | Correct | 13 ms | 3028 KB | Output is correct |
5 | Correct | 14 ms | 3176 KB | Output is correct |
6 | Correct | 11 ms | 3088 KB | Output is correct |
7 | Correct | 12 ms | 3028 KB | Output is correct |
8 | Execution timed out | 1081 ms | 3112 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1086 ms | 9036 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 3044 KB | Output is correct |
2 | Correct | 2 ms | 3048 KB | Output is correct |
3 | Correct | 18 ms | 3052 KB | Output is correct |
4 | Correct | 13 ms | 3028 KB | Output is correct |
5 | Correct | 14 ms | 3176 KB | Output is correct |
6 | Correct | 11 ms | 3088 KB | Output is correct |
7 | Correct | 12 ms | 3028 KB | Output is correct |
8 | Execution timed out | 1081 ms | 3112 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |