#include "crocodile.h"
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 112345, MAXM = 1123456;
std::vector<int> grafo [MAXN];
std::vector<int> grafop[MAXN];
int marc[MAXN];
priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int > > > q;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
for(int i = 0; i < M; i++){
int u, v, w;
u = R[i][0];
v = R[i][1];
w = L[i];
//printf("%d %d %d\n", u, v, w);
grafo[u].push_back(v);
grafo[v].push_back(u);
grafop[u].push_back(w);
grafop[v].push_back(w);
}
for(int i = 0; i < K; i++){
q.push(make_pair(0, P[i]));
marc[P[i]] = 1;
}
long long ans = 0;
while(!q.empty()){
int v = q.top().second;
long long c = q.top().first;
q.pop();
//printf("%d\n", v);
if(!marc[v]){
marc[v] = 1;
continue;
}if(marc[v] == 2) continue;
if(v == 0){
ans = c;
break;
}
marc[v] = 2;
for(int i = 0; i < grafo[v].size(); i++){
int viz = grafo[v][i];
//printf("%d\n", viz);
long long p = c + grafop[v][i];
if(marc[viz] == 2) continue;
q.push(make_pair(p, viz));
}
}
return (int) ans;
}
// int n, m;
// int r[MAXM][2], l[MAXM], k, p[MAXM];
// int main(){
// scanf("%d %d %d",&n, &m, &k );
// for(int i = 0; i < m; i++){
// scanf("%d %d %d", &r[i][0], &r[i][1], &l[i]);
// }for(int i = 0; i < k; i++){
// scanf("%d", &p[i]);
// }
// printf("%d\n",travel_plan(n,m,r,l,k,p) );
// }
Compilation message
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:50:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < grafo[v].size(); i++){
~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5632 KB |
Output is correct |
2 |
Correct |
8 ms |
5632 KB |
Output is correct |
3 |
Correct |
8 ms |
5632 KB |
Output is correct |
4 |
Correct |
8 ms |
5760 KB |
Output is correct |
5 |
Correct |
9 ms |
5760 KB |
Output is correct |
6 |
Correct |
8 ms |
5760 KB |
Output is correct |
7 |
Correct |
8 ms |
5760 KB |
Output is correct |
8 |
Correct |
8 ms |
5760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5632 KB |
Output is correct |
2 |
Correct |
8 ms |
5632 KB |
Output is correct |
3 |
Correct |
8 ms |
5632 KB |
Output is correct |
4 |
Correct |
8 ms |
5760 KB |
Output is correct |
5 |
Correct |
9 ms |
5760 KB |
Output is correct |
6 |
Correct |
8 ms |
5760 KB |
Output is correct |
7 |
Correct |
8 ms |
5760 KB |
Output is correct |
8 |
Correct |
8 ms |
5760 KB |
Output is correct |
9 |
Correct |
10 ms |
6016 KB |
Output is correct |
10 |
Correct |
8 ms |
5632 KB |
Output is correct |
11 |
Correct |
9 ms |
5760 KB |
Output is correct |
12 |
Correct |
13 ms |
6528 KB |
Output is correct |
13 |
Correct |
11 ms |
6144 KB |
Output is correct |
14 |
Correct |
8 ms |
5632 KB |
Output is correct |
15 |
Correct |
8 ms |
5760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5632 KB |
Output is correct |
2 |
Correct |
8 ms |
5632 KB |
Output is correct |
3 |
Correct |
8 ms |
5632 KB |
Output is correct |
4 |
Correct |
8 ms |
5760 KB |
Output is correct |
5 |
Correct |
9 ms |
5760 KB |
Output is correct |
6 |
Correct |
8 ms |
5760 KB |
Output is correct |
7 |
Correct |
8 ms |
5760 KB |
Output is correct |
8 |
Correct |
8 ms |
5760 KB |
Output is correct |
9 |
Correct |
10 ms |
6016 KB |
Output is correct |
10 |
Correct |
8 ms |
5632 KB |
Output is correct |
11 |
Correct |
9 ms |
5760 KB |
Output is correct |
12 |
Correct |
13 ms |
6528 KB |
Output is correct |
13 |
Correct |
11 ms |
6144 KB |
Output is correct |
14 |
Correct |
8 ms |
5632 KB |
Output is correct |
15 |
Correct |
8 ms |
5760 KB |
Output is correct |
16 |
Correct |
701 ms |
73944 KB |
Output is correct |
17 |
Correct |
111 ms |
17912 KB |
Output is correct |
18 |
Correct |
129 ms |
19624 KB |
Output is correct |
19 |
Correct |
853 ms |
77884 KB |
Output is correct |
20 |
Correct |
345 ms |
53276 KB |
Output is correct |
21 |
Correct |
60 ms |
11000 KB |
Output is correct |
22 |
Correct |
510 ms |
50040 KB |
Output is correct |