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 "crocodile.h"
#include<bits/stdc++.h>
using namespace std;
struct edge{
int to;
int w;
};
vector<edge> adjList[1005];
#define INF INT_MAX
int secondBest(int u,int p)
{
if(adjList[u].size()==1)
return 0;
int a=INF,b=INF;
for(edge e: adjList[u]){
int v=e.to;
if(v==p) continue;
int dist=secondBest(v,u);
if(dist+e.w<a){
b=a;
a=dist+e.w;
}
else if(dist+e.w<b){
b=dist+e.w;
}
}
return b;
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
for(int i=0;i<M;i++){
int u=R[i][0];
int v=R[i][1];
edge e={v,L[i]};
adjList[u].push_back(e);
e.to=u;
adjList[v].push_back(e);
}
int dist=secondBest(0,-1);
return dist;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |