/* 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;
#define ff first
#define ss second
const int MAXN=1001;
vector<pair<int,int>> adj[MAXN];
bool vis[MAXN];
bool leaf[MAXN];
void update(int NEW, int &FIR, int &SEC)
{
if(NEW<=FIR)
{
SEC=FIR;
FIR=NEW;
}
else
{
SEC=min(SEC,NEW);
}
}
int dfs(int v)
{
vis[v]=1;
int best=int(1e9);
int second_best=int(1e9);
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],L[i]));
adj[R[i][1]].push_back(make_pair(R[i][0],L[i]));
}
for(int i=0; i<K; i++)
{
leaf[P[i]]=1;
}
int ans=0;
for(int i=0; i<N; i++)
{
if(!leaf[i])
{
int cur=dfs(i);
// cout << i << " " << cur << endl;
ans=max(ans,cur);
for(int j=0; j<N; j++)
{
vis[j]=0;
}
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Incorrect |
3 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |