Submission #871018

#TimeUsernameProblemLanguageResultExecution timeMemory
871018Ahmed57Paths (RMI21_paths)C++17
8 / 100
2 ms600 KiB
#include <bits/stdc++.h> using namespace std; vector<pair<int,long long>> adj[101],tree[101]; long long ma = -1 , nod = 0; void dfs(int i,int pr,long long co){ if(ma<co){ ma = co; nod = i; } for(auto j:tree[i]){ if(j.first==pr)continue; dfs(j.first,i,co+j.second); } } long long all = 0; bool clea(int i,int pr){ if(i==nod)return 1; for(int j = 0;j<tree[i].size();j++){ if(tree[i][j].first==pr)continue; all+=tree[i][j].second; long long xd = tree[i][j].second; tree[i][j].second = 0; bool de = clea(tree[i][j].first,i); if(de==0){ all-=xd; tree[i][j].second = xd; }else{ return 1; } } return 0; } signed main(){ ios_base::sync_with_stdio(false);cin.tie(0); int n,k; cin>>n>>k; for(int i = 0;i<n-1;i++){ int a,b,c;cin>>a>>b>>c; adj[a].push_back({b,c}); adj[b].push_back({a,c}); } for(int r = 1;r<=n;r++){ for(int i = 1;i<=n;i++){ tree[i].clear(); for(auto w:adj[i]){ tree[i].push_back(w); } } int e = k; all = 0; while(e--){ ma = -1 , nod = 0; dfs(r,0,0); clea(r,0); } cout<<all<<endl; } }

Compilation message (stderr)

Main.cpp: In function 'bool clea(int, int)':
Main.cpp:18:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int j = 0;j<tree[i].size();j++){
      |                   ~^~~~~~~~~~~~~~~
#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...