#include "crocodile.h"
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
bool is[100005];
long long small[5][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};
long long ans=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 con)
{
long long t;
vector < pair < long long , long long > > tt;
//printf("%lld %lld\n",here,con);
if(is[here])
{
ans=con;
return 0;
}
for(auto i:Next[here]) if(small[1][i.first]!=-1) tt.push_back(make_pair(small[1][i.first],i.first));
sort(tt.begin(),tt.end());
if(tt.size()>=2)
{
return F(here,tt[1].second,con+how[here][tt[1].second]);
}
}
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];
}
for(i=0;i<N;i++)
{
small[0][i]=-1;
small[1][i]=-1;
}
for(i=0;i<K;i++)
{
is[P[i]]=1;
dij.push(make_pair(0,make_pair(P[i],-1)));
small[0][P[i]]=0;
small[1][P[i]]=0;
}
while(!dij.empty())
{
a=dij.top().first;
b=dij.top().second.first;
c=dij.top().second.second;
dij.pop();
if(is[b]&&small[0][b]==0)
{
small[0][b]=-2;
for(auto i:Next[b])
{
dij.push(make_pair(i.second+a,make_pair(i.first,b)));
}
}
else if(small[0][b]==-1) small[0][b]=a;
else if(small[1][b]==-1)
{
small[1][b]=a;
for(auto i:Next[b])
{
dij.push(make_pair(i.second+a,make_pair(i.first,b)));
}
}
else continue;
}
return small[1][0];
}
Compilation message
crocodile.cpp: In function 'long long int F(long long int, long long int, long long int)':
crocodile.cpp:18:15: warning: unused variable 't' [-Wunused-variable]
18 | long long t;
| ^
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:38:19: warning: variable 'c' set but not used [-Wunused-but-set-variable]
38 | long long a,b,c;
| ^
crocodile.cpp: In function 'long long int F(long long int, long long int, long long int)':
crocodile.cpp:19:47: warning: control reaches end of non-void function [-Wreturn-type]
19 | vector < pair < long long , long long > > tt;
| ^~
# |
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 |
9964 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 |
9964 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 |
12 ms |
11308 KB |
Output is correct |
10 |
Correct |
6 ms |
9836 KB |
Output is correct |
11 |
Correct |
9 ms |
10368 KB |
Output is correct |
12 |
Correct |
20 ms |
12392 KB |
Output is correct |
13 |
Correct |
17 ms |
12652 KB |
Output is correct |
14 |
Correct |
7 ms |
9836 KB |
Output is correct |
15 |
Correct |
9 ms |
10092 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 |
9964 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 |
12 ms |
11308 KB |
Output is correct |
10 |
Correct |
6 ms |
9836 KB |
Output is correct |
11 |
Correct |
9 ms |
10368 KB |
Output is correct |
12 |
Correct |
20 ms |
12392 KB |
Output is correct |
13 |
Correct |
17 ms |
12652 KB |
Output is correct |
14 |
Correct |
7 ms |
9836 KB |
Output is correct |
15 |
Correct |
9 ms |
10092 KB |
Output is correct |
16 |
Execution timed out |
2086 ms |
183964 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |