/* Arthur Conmy / arthurconmy */
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <random>
#include <stack>
#include <deque>
#include <chrono>
#ifndef ARTHUR_LOCAL
#include "crocodile.h"
#endif
using namespace std;
using ll = long long;
#define ff first
#define ss second
const int MAXN=1001;
vector<pair<int,ll>> adj[MAXN];
bool vis[MAXN];
bool leaf[MAXN];
void update(ll NEW, ll &FIR, ll &SEC)
{
if(NEW<=FIR)
{
SEC=FIR;
FIR=NEW;
}
else
{
SEC=min(SEC,NEW);
}
}
ll dfs(int v)
{
vis[v]=1;
ll best=1e18;
ll second_best=1e18;
for(auto u:adj[v])
{
if(vis[u.ff]) continue;
if(leaf[u.ff])
{
update(u.ss, best, second_best);
}
else
{
update(u.ss+dfs(u.ff), best, second_best);
}
}
return second_best;
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
for(int i=0; i<N-1; i++)
{
adj[R[i][0]].push_back(make_pair(R[i][1],ll(L[i])));
adj[R[i][1]].push_back(make_pair(R[i][0],ll(L[i])));
}
for(int i=0; i<K; i++)
{
leaf[P[i]]=1;
}
ll ans=0;
for(int i=0; i<N; i++)
{
if(!leaf[i])
{
ll cur=dfs(i);
// cout << i << " " << cur << endl;
ans=max(ans,cur);
for(int j=0; j<N; j++)
{
vis[j]=0;
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
4 ms |
504 KB |
Output is correct |
6 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
4 ms |
504 KB |
Output is correct |
6 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
4 ms |
504 KB |
Output is correct |
6 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |