#include "crocodile.h"
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]){
vector<pair<int,int> > adj[n];
long long a[n],b[n];
for(int i=0; i<n; i++){
a[i]=1e18;
b[i]=1e18;
}
int s[n];
memset(s,0,sizeof s);
for(int i=0; i<k; i++){
s[p[i]]=1;
}
for(int i=0; i<m; i++){
int x=r[i][0],y=r[i][1];
if(s[y]==1) swap(x,y);
long long sim=l[i];
if(s[x]==1){
if(a[y]>sim){
swap(a[y],sim);
}
if(b[y]>sim){
swap(b[y],sim);
}
}else {
adj[x].push_back(mp(y,sim));
adj[y].push_back(mp(x,sim));
}
}
priority_queue<pair<long long, long long> > pq;
for(int i=0; i<n; i++){
if(b[i]<1e18&&s[i]==0){
pq.push(mp(-b[i],i));
}
}
while(!pq.empty()){
long long x=-pq.top().fi,y=pq.top().se;
pq.pop();
if(x>b[y]) continue;
for(int i=0; i<adj[y].size(); i++){
long long z=adj[y][i].fi;
long long c=adj[y][i].se+x;
bool ada=0;
if(c<a[z]){
swap(c,a[z]);
}
if(c<b[z]){
ada=1;
swap(c,b[z]);
}
if(ada)pq.push(mp(-b[z],z));
}
}
return b[0];
}
Compilation message
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:47:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<adj[y].size(); i++){
~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
252 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
252 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
4 ms |
632 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
512 KB |
Output is correct |
12 |
Correct |
6 ms |
760 KB |
Output is correct |
13 |
Correct |
5 ms |
888 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
252 KB |
Output is correct |
4 |
Correct |
3 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
4 ms |
632 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
512 KB |
Output is correct |
12 |
Correct |
6 ms |
760 KB |
Output is correct |
13 |
Correct |
5 ms |
888 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
504 KB |
Output is correct |
16 |
Correct |
755 ms |
56256 KB |
Output is correct |
17 |
Correct |
98 ms |
14968 KB |
Output is correct |
18 |
Correct |
129 ms |
16476 KB |
Output is correct |
19 |
Correct |
781 ms |
64488 KB |
Output is correct |
20 |
Correct |
356 ms |
47556 KB |
Output is correct |
21 |
Correct |
50 ms |
6452 KB |
Output is correct |
22 |
Correct |
421 ms |
44784 KB |
Output is correct |