# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
628705 |
2022-08-13T15:42:03 Z |
bojackduy |
Toll (BOI17_toll) |
C++14 |
|
43 ms |
4564 KB |
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
const int N = 1e5 + 1;
const int inf = 1e9;
int k, n, m, q;
vii a[N];
pii b[N];
void subtask1() {
vi d(n + 1, inf);
priority_queue<pii, vector<pii>, greater<pii> > kew;
kew.push(pii(0, 0));
d[0] = 0;
while (kew.size()) {
int u = kew.top().se;
ll du = kew.top().fi;
kew.pop();
if (du > d[u]) continue;
for (pii v: a[u]) {
if (d[v.se] > du + v.fi) {
d[v.se] = du + v.fi;
kew.push(pii(d[v.se], v.se));
}
}
}
for (int i = 1; i <= q; i++) {
int x, y;
x = b[i].fi;
y = b[i].se;
if (x > y) {
cout << "-1\n";
continue;
}
cout << d[y] - (x <= 0 ? 0 : d[x - 1]) << '\n';
}
}
void subtask2() {
vi d(n + 1, inf);
priority_queue<pii, vector<pii>, greater<pii>> kew;
kew.push(pii(0, 0));
d[0] = 0;
while (kew.size()) {
int u = kew.top().se;
int du = kew.top().fi;
kew.pop();
if (du > d[u]) continue;
for (pii v: a[u]) {
if (d[v.se] > du + v.fi) {
d[v.se] = du + v.fi;
kew.push(pii(d[v.se], v.se));
}
}
}
for (int i = 1; i <= q; i++) {
if (d[b[i].se] == inf) {
cout << -1 << '\n';
} else cout << d[b[i].se] << '\n';
}
}
void subtask3() {
for (int i = 1; i <= q; i++) {
int x, y;
x = b[i].fi;
y = b[i].se;
vi d(n + 1, inf);
priority_queue<pii, vector<pii>, greater<pii>> kew;
kew.push(pii(0, x));
d[x] = 0;
while (kew.size()) {
int u = kew.top().se;
int du = kew.top().fi;
if (u == y) {
cout << d[u] << '\n';
break;
}
kew.pop();
if (du > d[u]) continue;
for (pli v: a[u]) {
if (d[v.se] > du + v.fi) {
d[v.se] = du + v.fi;
kew.push(pii(d[v.se], v.se));
}
}
}
if (d[y] == inf) cout << "-1\n";
}
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> k >> n >> m >> q;
for (int i = 1; i <= m; i++) {
int x, y, z;
cin >> x >> y >> z;
a[x].pb(pii(z, y));
}
int cnt = 0;
for (int i = 1; i <= q; i++) {
cin >> b[i].fi >> b[i].se;
if (b[i].fi == 0) cnt++;
}
if (k == 1) {
subtask1();
return 0;
}
if (cnt == q) {
subtask2();
return 0;
}
subtask3();
return 0;
}
/*
5 14 5 5
0 5 9
5 12 10
0 7 7
7 12 8
4 7 10
0 12
0 5
0 7
7 12
0 13
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
4564 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
4556 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
4564 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |