QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#94674 | #5613. Road To Savings | PetroTarnavskyi# | AC ✓ | 6ms | 3532kb | C++17 | 1.1kb | 2023-04-07 14:56:17 | 2023-04-07 14:56:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int INF = 1e9;
const int N = 107;
int d[N][N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, s, t;
cin >> n >> m >> s >> t;
s--;
t--;
FOR(i, 0, n) {
FOR(j, 0, n) {
d[i][j] = i == j ? 0 : INF;
}
}
vector<tuple<int, int, int>> edges(m);
FOR(i, 0, m) {
auto& [u, v, w] = edges[i];
cin >> u >> v >> w;
u--;
v--;
d[u][v] = d[v][u] = w;
}
FOR(k, 0, n) {
FOR(i, 0, n) {
FOR(j, 0, n) {
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
int ans = 0;
for (auto [u, v, w] : edges) {
if (min(d[s][u] + d[t][v], d[s][v] + d[t][u]) + w != d[s][t]) {
ans += w;
}
}
cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 3324kb
input:
4 5 1 4 1 2 1 1 3 2 1 4 2 4 2 1 3 4 1
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 3ms
memory: 3380kb
input:
4 5 1 4 1 2 1 1 3 2 1 4 1 4 2 1 3 4 1
output:
5
result:
ok single line: '5'
Test #3:
score: 0
Accepted
time: 3ms
memory: 3328kb
input:
2 1 1 2 1 2 10
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 3ms
memory: 3304kb
input:
3 3 1 2 1 2 10 2 3 10 3 1 10
output:
20
result:
ok single line: '20'
Test #5:
score: 0
Accepted
time: 3ms
memory: 3372kb
input:
3 3 1 2 1 2 10 2 3 5 3 1 5
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 6ms
memory: 3532kb
input:
100 4950 74 24 1 2 8 1 3 6 1 4 5 1 5 6 1 6 2 1 7 6 1 8 1 1 9 10 1 10 1 1 11 10 1 12 9 1 13 4 1 14 4 1 15 1 1 16 4 1 17 7 1 18 8 1 19 1 1 20 7 1 21 2 1 22 9 1 23 9 1 24 7 1 25 6 1 26 5 1 27 4 1 28 3 1 29 4 1 30 6 1 31 8 1 32 10 1 33 10 1 34 3 1 35 6 1 36 10 1 37 5 1 38 4 1 39 1 1 40 10 1 41 9 1 42 7 ...
output:
27615
result:
ok single line: '27615'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3380kb
input:
40 780 6 12 1 2 100 1 3 100 1 4 100 1 5 100 1 6 100 1 7 100 1 8 100 1 9 100 1 10 100 1 11 100 1 12 100 1 13 100 1 14 100 1 15 100 1 16 100 1 17 100 1 18 100 1 19 100 1 20 1 1 21 100 1 22 100 1 23 100 1 24 100 1 25 100 1 26 1 1 27 100 1 28 100 1 29 100 1 30 100 1 31 100 1 32 100 1 33 100 1 34 100 1 3...
output:
74100
result:
ok single line: '74100'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3356kb
input:
40 780 6 12 1 2 100 1 3 100 1 4 100 1 5 100 1 6 1 1 7 100 1 8 100 1 9 100 1 10 100 1 11 100 1 12 100 1 13 100 1 14 100 1 15 100 1 16 100 1 17 100 1 18 100 1 19 100 1 20 100 1 21 100 1 22 100 1 23 100 1 24 100 1 25 100 1 26 1 1 27 100 1 28 100 1 29 100 1 30 100 1 31 100 1 32 100 1 33 100 1 34 100 1 3...
output:
74000
result:
ok single line: '74000'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3332kb
input:
40 780 6 12 1 2 100 1 3 100 1 4 100 1 5 100 1 6 100 1 7 100 1 8 100 1 9 100 1 10 100 1 11 100 1 12 100 1 13 100 1 14 100 1 15 100 1 16 100 1 17 100 1 18 100 1 19 100 1 20 100 1 21 100 1 22 100 1 23 100 1 24 100 1 25 100 1 26 100 1 27 100 1 28 100 1 29 100 1 30 100 1 31 100 1 32 100 1 33 100 1 34 100...
output:
77900
result:
ok single line: '77900'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3428kb
input:
13 16 1 6 1 2 1 1 7 2 1 8 2 1 9 2 1 10 1 2 3 1 3 4 1 4 5 1 5 6 1 7 6 2 8 6 2 9 6 2 10 11 1 11 12 1 12 13 1 13 6 1
output:
10
result:
ok single line: '10'
Test #11:
score: 0
Accepted
time: 2ms
memory: 3456kb
input:
54 60 1 2 1 2 24 1 3 12 3 2 12 1 4 8 4 5 8 5 2 8 1 6 6 6 7 6 7 8 6 8 2 6 1 9 4 9 10 4 10 11 4 11 12 4 12 13 4 13 2 4 1 14 3 14 15 3 15 16 3 16 17 3 17 18 3 18 19 3 19 20 3 20 2 3 1 21 2 21 22 2 22 23 2 23 24 2 24 25 2 25 26 2 26 27 2 27 28 2 28 29 2 29 30 2 30 31 2 31 2 2 1 32 1 32 33 1 33 34 1 34 3...
output:
0
result:
ok single line: '0'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3356kb
input:
54 60 1 2 1 2 25 1 3 12 3 2 12 1 4 8 4 5 8 5 2 8 1 6 6 6 7 6 7 8 6 8 2 6 1 9 4 9 10 4 10 11 4 11 12 4 12 13 4 13 2 4 1 14 3 14 15 3 15 16 3 16 17 3 17 18 3 18 19 3 19 20 3 20 2 3 1 21 2 21 22 2 22 23 2 23 24 2 24 25 2 25 26 2 26 27 2 27 28 2 28 29 2 29 30 2 30 31 2 31 2 2 1 32 1 32 33 1 33 34 1 34 3...
output:
25
result:
ok single line: '25'
Test #13:
score: 0
Accepted
time: 3ms
memory: 3472kb
input:
96 4560 95 45 1 2 3 1 3 3 1 4 3 1 5 3 1 6 3 1 7 3 1 8 3 1 9 2 1 10 1 1 11 2 1 12 2 1 13 3 1 14 1 1 15 2 1 16 3 1 17 3 1 18 3 1 19 2 1 20 2 1 21 2 1 22 3 1 23 3 1 24 1 1 25 2 1 26 3 1 27 3 1 28 3 1 29 1 1 30 2 1 31 2 1 32 2 1 33 1 1 34 2 1 35 2 1 36 3 1 37 2 1 38 1 1 39 2 1 40 3 1 41 2 1 42 1 1 43 1 ...
output:
9137
result:
ok single line: '9137'
Test #14:
score: 0
Accepted
time: 2ms
memory: 3488kb
input:
68 2278 60 17 1 2 1 1 3 1 1 4 1 1 5 2 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1 1 11 3 1 12 3 1 13 3 1 14 3 1 15 3 1 16 2 1 17 3 1 18 2 1 19 3 1 20 2 1 21 1 1 22 1 1 23 2 1 24 3 1 25 1 1 26 3 1 27 3 1 28 3 1 29 1 1 30 3 1 31 1 1 32 1 1 33 1 1 34 2 1 35 3 1 36 2 1 37 1 1 38 2 1 39 1 1 40 1 1 41 3 1 42 1 1 43 2 ...
output:
4581
result:
ok single line: '4581'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
92 4186 55 9 1 2 1 1 3 3 1 4 2 1 5 3 1 6 3 1 7 1 1 8 3 1 9 1 1 10 2 1 11 1 1 12 2 1 13 3 1 14 1 1 15 3 1 16 3 1 17 2 1 18 1 1 19 1 1 20 1 1 21 3 1 22 3 1 23 1 1 24 1 1 25 3 1 26 3 1 27 2 1 28 1 1 29 1 1 30 2 1 31 2 1 32 3 1 33 1 1 34 3 1 35 2 1 36 2 1 37 1 1 38 1 1 39 2 1 40 1 1 41 1 1 42 2 1 43 3 1...
output:
8396
result:
ok single line: '8396'
Test #16:
score: 0
Accepted
time: 3ms
memory: 3400kb
input:
98 4753 62 63 1 2 3 1 3 1 1 4 1 1 5 1 1 6 1 1 7 3 1 8 3 1 9 3 1 10 2 1 11 1 1 12 2 1 13 1 1 14 3 1 15 2 1 16 3 1 17 2 1 18 1 1 19 2 1 20 1 1 21 3 1 22 3 1 23 3 1 24 1 1 25 2 1 26 1 1 27 3 1 28 2 1 29 1 1 30 1 1 31 2 1 32 2 1 33 3 1 34 2 1 35 3 1 36 3 1 37 2 1 38 2 1 39 2 1 40 3 1 41 2 1 42 3 1 43 3 ...
output:
9488
result:
ok single line: '9488'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3364kb
input:
68 2278 62 34 1 2 2 1 3 1 1 4 1 1 5 1 1 6 3 1 7 2 1 8 3 1 9 3 1 10 3 1 11 1 1 12 2 1 13 2 1 14 1 1 15 2 1 16 3 1 17 1 1 18 2 1 19 1 1 20 2 1 21 1 1 22 1 1 23 2 1 24 1 1 25 2 1 26 3 1 27 3 1 28 1 1 29 3 1 30 2 1 31 2 1 32 3 1 33 1 1 34 2 1 35 3 1 36 1 1 37 2 1 38 2 1 39 1 1 40 3 1 41 3 1 42 1 1 43 1 ...
output:
4605
result:
ok single line: '4605'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3424kb
input:
67 2211 46 47 1 2 3 1 3 2 1 4 2 1 5 1 1 6 1 1 7 1 1 8 3 1 9 2 1 10 1 1 11 2 1 12 2 1 13 3 1 14 2 1 15 3 1 16 3 1 17 1 1 18 2 1 19 3 1 20 3 1 21 3 1 22 1 1 23 1 1 24 3 1 25 2 1 26 3 1 27 1 1 28 3 1 29 3 1 30 3 1 31 3 1 32 1 1 33 2 1 34 1 1 35 2 1 36 3 1 37 3 1 38 3 1 39 2 1 40 2 1 41 1 1 42 3 1 43 3 ...
output:
4439
result:
ok single line: '4439'
Test #19:
score: 0
Accepted
time: 2ms
memory: 3440kb
input:
67 2211 17 50 1 2 3 1 3 3 1 4 1 1 5 1 1 6 3 1 7 2 1 8 2 1 9 2 1 10 1 1 11 3 1 12 3 1 13 2 1 14 3 1 15 3 1 16 1 1 17 2 1 18 2 1 19 1 1 20 3 1 21 2 1 22 3 1 23 2 1 24 2 1 25 3 1 26 2 1 27 1 1 28 2 1 29 3 1 30 3 1 31 3 1 32 1 1 33 3 1 34 2 1 35 1 1 36 3 1 37 2 1 38 2 1 39 1 1 40 3 1 41 3 1 42 3 1 43 1 ...
output:
4428
result:
ok single line: '4428'
Test #20:
score: 0
Accepted
time: 1ms
memory: 3344kb
input:
74 2701 61 70 1 2 1 1 3 2 1 4 2 1 5 2 1 6 2 1 7 3 1 8 3 1 9 3 1 10 1 1 11 2 1 12 1 1 13 2 1 14 1 1 15 2 1 16 3 1 17 1 1 18 2 1 19 3 1 20 1 1 21 2 1 22 3 1 23 2 1 24 3 1 25 3 1 26 1 1 27 3 1 28 3 1 29 3 1 30 1 1 31 2 1 32 3 1 33 1 1 34 1 1 35 1 1 36 3 1 37 2 1 38 3 1 39 1 1 40 2 1 41 3 1 42 1 1 43 3 ...
output:
5420
result:
ok single line: '5420'
Test #21:
score: 0
Accepted
time: 2ms
memory: 3372kb
input:
77 2926 54 68 1 2 2 1 3 3 1 4 2 1 5 2 1 6 1 1 7 3 1 8 3 1 9 1 1 10 3 1 11 1 1 12 3 1 13 3 1 14 3 1 15 3 1 16 3 1 17 1 1 18 1 1 19 2 1 20 1 1 21 2 1 22 2 1 23 3 1 24 1 1 25 1 1 26 3 1 27 1 1 28 3 1 29 1 1 30 1 1 31 3 1 32 3 1 33 3 1 34 3 1 35 3 1 36 1 1 37 1 1 38 1 1 39 2 1 40 3 1 41 3 1 42 1 1 43 3 ...
output:
5867
result:
ok single line: '5867'
Test #22:
score: 0
Accepted
time: 3ms
memory: 3396kb
input:
84 3486 17 46 1 2 2 1 3 3 1 4 3 1 5 1 1 6 1 1 7 2 1 8 2 1 9 3 1 10 3 1 11 1 1 12 1 1 13 3 1 14 2 1 15 1 1 16 1 1 17 1 1 18 1 1 19 1 1 20 2 1 21 3 1 22 3 1 23 1 1 24 3 1 25 1 1 26 3 1 27 3 1 28 1 1 29 2 1 30 3 1 31 1 1 32 2 1 33 2 1 34 1 1 35 3 1 36 2 1 37 3 1 38 3 1 39 1 1 40 1 1 41 3 1 42 2 1 43 3 ...
output:
7034
result:
ok single line: '7034'
Test #23:
score: 0
Accepted
time: 2ms
memory: 3420kb
input:
4 2 1 2 1 2 10 3 4 5
output:
5
result:
ok single line: '5'
Test #24:
score: 0
Accepted
time: 2ms
memory: 3372kb
input:
30 379 15 27 1 2 8 1 3 46 1 4 16 1 5 2 1 6 27 1 7 84 1 8 1 1 9 53 1 10 56 1 11 78 1 12 56 1 13 67 1 14 21 1 16 43 1 17 44 1 18 10 1 19 36 1 20 61 1 21 80 1 22 46 1 23 9 1 24 53 1 25 72 1 26 34 1 28 71 1 29 68 1 30 16 2 3 96 2 4 99 2 5 23 2 6 86 2 7 24 2 8 17 2 9 27 2 10 70 2 11 88 2 12 31 2 13 94 2 ...
output:
19360
result:
ok single line: '19360'
Test #25:
score: 0
Accepted
time: 2ms
memory: 3272kb
input:
30 210 26 28 1 3 32 1 5 65 1 7 29 1 9 44 1 11 26 1 13 24 1 15 22 1 17 86 1 19 25 1 21 33 1 23 33 1 25 21 1 27 92 1 29 44 2 4 14 2 6 51 2 8 70 2 10 80 2 12 92 2 14 50 2 16 89 2 18 75 2 20 14 2 22 7 2 24 30 2 26 64 2 28 97 2 30 84 3 5 39 3 7 1 3 9 58 3 11 39 3 13 49 3 15 69 3 17 30 3 19 97 3 21 67 3 2...
output:
11126
result:
ok single line: '11126'