#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
typedef long long ll;
typedef pair<ll, int> ii;
const int N = 1e5 + 10;
vector<int> adj[N], cost[N];
ll d1[N], d2[N];
int p1[N], p2[N];
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 = R[i][0], v = R[i][1], c = L[i];
adj[u].push_back(v);
adj[v].push_back(u);
cost[u].push_back(c);
cost[v].push_back(c);
}
memset(d1, 127, sizeof d1);
memset(d2, 127, sizeof d2);
priority_queue<ii, vector<ii>, greater<ii> > Q;
for(int i = 0; i < K; i++) {
int u = P[i];
d1[u] = d2[u] = 0;
p1[u] = p2[u] = u;
Q.emplace(0, u);
}
while(!Q.empty()) {
ii x = Q.top(); Q.pop();
int u = x.second; ll d = x.first;
for(int i = 0; i < adj[u].size(); i++) {
int v = adj[u][i], c = cost[u][i];
if(d2[v] > d + c) {
d2[v] = d + c;
p2[v] = u;
Q.emplace(d2[v], v);
if(d2[v] < d1[v]) {
swap(d1[v], d2[v]);
swap(p1[v], p2[v]);
}
}
}
}
int u = 0;
int tot = 0;
while(p2[u] != u) {
cout << u << " " << tot << endl;
for(int i = 0; i < adj[u].size(); i++) {
int v = adj[u][i];
if(v == p2[u]) {
tot += cost[u][i];
u = v;
break;
}
}
}
return tot;
}
Compilation message
crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:36:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < adj[u].size(); i++) {
~~^~~~~~~~~~~~~~~
crocodile.cpp:54:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < adj[u].size(); i++) {
~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2041 ms |
15968 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2041 ms |
15968 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2041 ms |
15968 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |