This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+45;
int n,m,k;
vector <pair<int,ll>> g[N];
bool ex[N];
ll dp1[N];
void dfs(int x,int par){
vector <ll> svi;
for(auto f : g[x]){
int u = f.first;
if(u == par) continue;
ll w = f.second;
dfs(u,x);
svi.push_back(dp1[u]+w);
}
if(svi.empty()) return;
//assert(svi.size() >= 2);
if(svi.size() == 1){
dp1[x] = 1e15;
return;
}
sort(svi.begin(),svi.end());
dp1[x] = svi[1];
}
int zadrvo(){
dfs(1,0);
return dp1[1];
}
int travel_plan(int br,int M,int R[][2],int L[],int K,int P[]){
n = br;
m = M;
k = K;
for(int i = 0; i < m; i++){
g[R[i][0]+1].push_back({R[i][1]+1,L[i]});
g[R[i][1]+1].push_back({R[i][0]+1,L[i]});
}
for(int i = 0; i < k; i++){
ex[P[i]+1] = 1;
}
return zadrvo();
}
/*int grane[10*N][2],tezine[10*N],izlazi[N];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int br1,br2,br3;
cin >> br1 >> br2 >> br3;
for(int i = 0; i < br2; i++){
cin >> grane[i][0] >> grane[i][1] >> tezine[i];
}
for(int i = 0; i < br3; i++) cin >> izlazi[i];
cout << travel_plan(br1,br2,grane,tezine,br3,izlazi) << endl;
}*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |