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;
const int NN = 1e5 + 7;
vector < pair < int, int > > adj[NN];
int dp[NN], l[NN], used[NN], isExit[NN];
void dfs( int v ) {
int mn1 = 1e9, mn2 = 1e9;
used[v] = 1;
// cout << "-> " << v << ' ' << p << '\n';
for ( auto pr: adj[v] ) {
int u = pr.first, ind = pr.second;
if ( !used[u] ) {
dfs( u );
int cnt = dp[u] + l[ind];
if ( cnt <= mn1 ) {
mn2 = mn1;
mn1 = cnt;
}
else if ( cnt < mn2 ) {
mn2 = cnt;
}
}
}
if ( mn2 == 1e9 ) {
mn2 = mn1;
}
if ( mn2 == 1e9 ) {
mn2 = 0;
}
if ( isExit[v] ) {
mn2 = 0;
}
// cout << "-> " << v << ' ' << mn1 << ' ' << mn2 << '\n';
dp[v] = mn2;
}
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], v = R[i][1];
adj[u].push_back( { v, i } );
adj[v].push_back( { u, i } );
l[i] = L[i];
}
for ( int i = 0; i < K; i++ ) {
isExit[ P[i] ] = 1;
}
dfs( 0 );
return dp[0];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |