QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#325098#5613. Road To Savingstom0727AC ✓1ms4140kbC++201.4kb2024-02-11 04:14:122024-02-11 04:14:13

Judging History

你现在查看的是最新测评结果

  • [2024-02-11 04:14:13]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:4140kb
  • [2024-02-11 04:14:12]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define pb push_back
typedef pair<int, int> pii;

const int maxn = 111;

int n, m, s, t, diss[maxn], dist[maxn], head[maxn];
bool vis[maxn];

struct edge {
    int u, v, w, nxt;
} e[maxn * maxn];

void dijkstra(int* dis, int start) {
    memset(vis, 0, sizeof(vis));

    dis[start] = 0;

    priority_queue<pii, vector<pii>, greater<pii>> pq;

    pq.push({0, start});

    while (! pq.empty()) {
        auto [_, u] = pq.top();
        pq.pop();

        if (vis[u]) continue;

        vis[u] = 1;

        for (int i = head[u], v; ~i; i = e[i].nxt) {
            v = e[i].v;

            if (dis[v] > dis[u] + e[i].w) {
                dis[v] = dis[u] + e[i].w;
                pq.push({dis[v], v});
            }
        }
    }
}

int main() {
    scanf("%d%d%d%d", &n, &m, &s, &t);
    memset(head, 0xff, sizeof(head));

    memset(diss, 0x1f, sizeof(diss));
    memset(dist, 0x1f, sizeof(dist));

    int sum = 0;

    for (int i = 0, u, v, w; i < m; i++)
        scanf("%d%d%d", &u, &v, &w), sum += w, e[i << 1] = {u, v, w, head[u]}, head[u] = i << 1, e[i << 1 | 1] = {v, u, w, head[v]}, head[v] = i << 1 | 1; 

    dijkstra(diss, s), dijkstra(dist, t);

    for (int i = 0; i < m; i++) {
        auto [u, v, w, _] = e[i << 1];

        if (diss[u] + w + dist[v] == diss[t] || dist[u] + w + diss[v] == diss[t]) sum -= w;
    }

    printf("%d\n", sum);
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 4012kb

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: 0ms
memory: 3748kb

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: 0ms
memory: 3828kb

input:

2 1 1 2
1 2 10

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3752kb

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: 0ms
memory: 3768kb

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: 1ms
memory: 3920kb

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: 1ms
memory: 3788kb

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: 0ms
memory: 3784kb

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: 0ms
memory: 3792kb

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: 0ms
memory: 4032kb

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: 0ms
memory: 3764kb

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: 3740kb

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: 1ms
memory: 3968kb

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: 1ms
memory: 3828kb

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: 1ms
memory: 4140kb

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: 0ms
memory: 3868kb

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: 1ms
memory: 3776kb

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: 1ms
memory: 4080kb

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: 1ms
memory: 3824kb

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: 4060kb

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: 1ms
memory: 3804kb

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: 1ms
memory: 3876kb

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: 0ms
memory: 3712kb

input:

4 2 1 2
1 2 10
3 4 5

output:

5

result:

ok single line: '5'

Test #24:

score: 0
Accepted
time: 0ms
memory: 4036kb

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: 0ms
memory: 3712kb

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'