#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <set>
#include <cmath>
#include <climits>
#include <cstring>
#include "crocodile.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
vector<vector<ii>> adjList(100007, vector<ii>());
const int INF = 1e9 + 7;
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]){
for (ll i = 0; i < m; i++){
adjList[r[i][0]].push_back(make_pair(r[i][1], l[i]));
adjList[r[i][1]].push_back(make_pair(r[i][0], l[i]));
}
vector<ii> t(n, {INF, INF});
priority_queue<ii, vector<ii>, greater<ii>> pq;
for (ll i = 0; i < k; i++){
t[p[i]] = {0, 0};
pq.push({0, p[i]});
}
while(!pq.empty()){
auto curr = pq.top();
pq.pop();
if (t[curr.second].first < curr.first)
continue;
for (ll i = 0; i < adjList[curr.second].size(); i++){
ll d = adjList[curr.second][i].second, idx = adjList[curr.second][i].first;
ll val = t[curr.second].first + d;
if (val <= t[idx].second){
t[idx].first = t[idx].second;
t[idx].second = val;
pq.push({t[idx].first, idx});
}
else if (val < t[idx].first){
t[idx].first = val;
pq.push({t[idx].first, idx});
}
}
}
return t[0].first;
}
Compilation message
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:38:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (ll i = 0; i < adjList[curr.second].size(); i++){
~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2816 KB |
Output is correct |
5 |
Correct |
2 ms |
2816 KB |
Output is correct |
6 |
Correct |
2 ms |
2816 KB |
Output is correct |
7 |
Correct |
2 ms |
2816 KB |
Output is correct |
8 |
Correct |
2 ms |
2816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2816 KB |
Output is correct |
5 |
Correct |
2 ms |
2816 KB |
Output is correct |
6 |
Correct |
2 ms |
2816 KB |
Output is correct |
7 |
Correct |
2 ms |
2816 KB |
Output is correct |
8 |
Correct |
2 ms |
2816 KB |
Output is correct |
9 |
Correct |
4 ms |
3072 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
3 ms |
2816 KB |
Output is correct |
12 |
Correct |
6 ms |
3328 KB |
Output is correct |
13 |
Correct |
5 ms |
3456 KB |
Output is correct |
14 |
Correct |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 ms |
2816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2816 KB |
Output is correct |
5 |
Correct |
2 ms |
2816 KB |
Output is correct |
6 |
Correct |
2 ms |
2816 KB |
Output is correct |
7 |
Correct |
2 ms |
2816 KB |
Output is correct |
8 |
Correct |
2 ms |
2816 KB |
Output is correct |
9 |
Correct |
4 ms |
3072 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
3 ms |
2816 KB |
Output is correct |
12 |
Correct |
6 ms |
3328 KB |
Output is correct |
13 |
Correct |
5 ms |
3456 KB |
Output is correct |
14 |
Correct |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 ms |
2816 KB |
Output is correct |
16 |
Correct |
572 ms |
68712 KB |
Output is correct |
17 |
Correct |
124 ms |
16620 KB |
Output is correct |
18 |
Correct |
142 ms |
18904 KB |
Output is correct |
19 |
Correct |
755 ms |
77160 KB |
Output is correct |
20 |
Correct |
364 ms |
54520 KB |
Output is correct |
21 |
Correct |
51 ms |
9080 KB |
Output is correct |
22 |
Incorrect |
417 ms |
50664 KB |
Output isn't correct |