Submission #537539

#TimeUsernameProblemLanguageResultExecution timeMemory
537539jamezzzPaths (RMI21_paths)C++17
19 / 100
1086 ms9036 KiB
#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 (stderr)

Main.cpp: In function 'int main()':
Main.cpp:44:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |  sf("%d%d",&n,&k);
      |    ^
Main.cpp:46:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |   sf("%d%d%d",&x[i],&y[i],&c[i]);
      |     ^
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...