#include "crocodile.h"
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
bool is[100005];
vector < pair < long long , long long > > Next[100005];
vector < pair < long long , long long > > Next2[100005];
map < long long , long long > how[100005];
bool have[100005]={0};
priority_queue < pair < long long , pair < long long , long long > > , vector < pair < long long , pair < long long , long long > > > , greater < pair < long long , pair < long long , long long > > > > dij;
long long F(long long fa,long long here)
{
long long t;
vector < long long > tt;
if(is[here]) return 0;
for(auto i:Next2[here])
{
if(i.first!=fa)
{
t=F(here,i.first);
if(t!=-1) tt.push_back(t+i.second);
}
}
sort(tt.begin(),tt.end());
if(tt.size()>=2) return tt[1];
else return -1;
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
int i;
long long a,b,c;
for(i=0;i<M;i++)
{
Next[R[i][0]].push_back(make_pair((long long) R[i][1],(long long) L[i]));
Next[R[i][1]].push_back(make_pair((long long) R[i][0],(long long) L[i]));
how[R[i][0]][R[i][1]]=L[i];
how[R[i][1]][R[i][0]]=L[i];
}
dij.push(make_pair(0,make_pair(0,-1)));
while(!dij.empty())
{
a=dij.top().first;
b=dij.top().second.first;
c=dij.top().second.second;
dij.pop();
if(have[b]) continue;
have[b]=1;
if(c!=-1) Next2[c].push_back(make_pair(b,how[b][c]));
for(auto i:Next[b])
{
dij.push(make_pair(i.second+a,make_pair(i.first,b)));
}
}
for(i=0;i<K;i++) is[P[i]]=1;
return (int) F(-1,0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9708 KB |
Output is correct |
2 |
Correct |
7 ms |
9708 KB |
Output is correct |
3 |
Correct |
7 ms |
9856 KB |
Output is correct |
4 |
Correct |
8 ms |
9976 KB |
Output is correct |
5 |
Correct |
8 ms |
9964 KB |
Output is correct |
6 |
Correct |
8 ms |
9964 KB |
Output is correct |
7 |
Correct |
8 ms |
9964 KB |
Output is correct |
8 |
Correct |
8 ms |
9964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9708 KB |
Output is correct |
2 |
Correct |
7 ms |
9708 KB |
Output is correct |
3 |
Correct |
7 ms |
9856 KB |
Output is correct |
4 |
Correct |
8 ms |
9976 KB |
Output is correct |
5 |
Correct |
8 ms |
9964 KB |
Output is correct |
6 |
Correct |
8 ms |
9964 KB |
Output is correct |
7 |
Correct |
8 ms |
9964 KB |
Output is correct |
8 |
Correct |
8 ms |
9964 KB |
Output is correct |
9 |
Correct |
13 ms |
11180 KB |
Output is correct |
10 |
Incorrect |
7 ms |
9836 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
9708 KB |
Output is correct |
2 |
Correct |
7 ms |
9708 KB |
Output is correct |
3 |
Correct |
7 ms |
9856 KB |
Output is correct |
4 |
Correct |
8 ms |
9976 KB |
Output is correct |
5 |
Correct |
8 ms |
9964 KB |
Output is correct |
6 |
Correct |
8 ms |
9964 KB |
Output is correct |
7 |
Correct |
8 ms |
9964 KB |
Output is correct |
8 |
Correct |
8 ms |
9964 KB |
Output is correct |
9 |
Correct |
13 ms |
11180 KB |
Output is correct |
10 |
Incorrect |
7 ms |
9836 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |