Submission #537579

#TimeUsernameProblemLanguageResultExecution timeMemory
537579tqbfjotldPaths (RMI21_paths)C++14
12 / 100
184 ms35916 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int K; map<int,int > memo[100005]; vector<pair<int,int> > adjl[100005]; int dfs(int node, int pa, bool ig){ if (memo[node].count(pa)) return memo[node][pa]; int ans = 0; int ans2 = -999999999; int from1 = node; for (auto x : adjl[node]){ if (ig && x.first==pa) continue; auto res = dfs(x.first,node,ig)+x.second; if (res>=ans){ from1 = x.first; ans2 = ans; ans = res; } else if (res>=ans2){ ans2 = res; } } if (ig){ return memo[node][pa] = ans; } for (auto x : adjl[node]){ if (x.first==from1) memo[node][x.first] = ans2; else memo[node][x.first] = ans; } memo[node][0] = ans; return memo[node][pa]; } main(){ int n; scanf("%lld%lld",&n,&K); for (int x = 0; x<n-1; x++){ int a,b,c; scanf("%lld%lld%lld",&a,&b,&c); adjl[a].push_back({b,c}); adjl[b].push_back({a,c}); } for (int x = 1; x<=n; x++){ auto res = dfs(x,0,x==1); int ans = res; printf("%lld\n",ans); } }

Compilation message (stderr)

Main.cpp:38:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   38 | main(){
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |     scanf("%lld%lld",&n,&K);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
Main.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         scanf("%lld%lld%lld",&a,&b,&c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...