#include "crocodile.h"
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
bool is[100005];
bool vis[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[5][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)
{
vis[here]=1;
long long t;
vector < long long > tt;
if(is[here]) return 0;
for(auto i:Next2[here])
{
if(!vis[i.first])
{
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[0][b]==0) have[0][b]=1;
else if(have[1][b]==0) have[1][b]=1;
else continue;
if(c!=-1) Next2[c].push_back(make_pair(b,how[b][c]));
for(auto i:Next[b])
{
if(i.first!=c) 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);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9708 KB |
Output is correct |
2 |
Correct |
6 ms |
9708 KB |
Output is correct |
3 |
Correct |
7 ms |
9836 KB |
Output is correct |
4 |
Correct |
7 ms |
9964 KB |
Output is correct |
5 |
Correct |
7 ms |
9984 KB |
Output is correct |
6 |
Correct |
7 ms |
9964 KB |
Output is correct |
7 |
Correct |
7 ms |
9964 KB |
Output is correct |
8 |
Correct |
7 ms |
9964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9708 KB |
Output is correct |
2 |
Correct |
6 ms |
9708 KB |
Output is correct |
3 |
Correct |
7 ms |
9836 KB |
Output is correct |
4 |
Correct |
7 ms |
9964 KB |
Output is correct |
5 |
Correct |
7 ms |
9984 KB |
Output is correct |
6 |
Correct |
7 ms |
9964 KB |
Output is correct |
7 |
Correct |
7 ms |
9964 KB |
Output is correct |
8 |
Correct |
7 ms |
9964 KB |
Output is correct |
9 |
Correct |
14 ms |
11624 KB |
Output is correct |
10 |
Incorrect |
6 ms |
9836 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9708 KB |
Output is correct |
2 |
Correct |
6 ms |
9708 KB |
Output is correct |
3 |
Correct |
7 ms |
9836 KB |
Output is correct |
4 |
Correct |
7 ms |
9964 KB |
Output is correct |
5 |
Correct |
7 ms |
9984 KB |
Output is correct |
6 |
Correct |
7 ms |
9964 KB |
Output is correct |
7 |
Correct |
7 ms |
9964 KB |
Output is correct |
8 |
Correct |
7 ms |
9964 KB |
Output is correct |
9 |
Correct |
14 ms |
11624 KB |
Output is correct |
10 |
Incorrect |
6 ms |
9836 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |