QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#681301#5613. Road To Savingsvic233333#AC ✓2ms3916kbC++202.0kb2024-10-27 04:28:062024-10-27 04:28:07

Judging History

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

  • [2024-10-27 04:28:07]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:3916kb
  • [2024-10-27 04:28:06]
  • 提交

answer

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

const int N = 110, M = N * N;

#define int long long

int n, m, s, t;
int f[N][N];
int u[M], v[M], wt[M];

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n >> m >> s >> t;

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            f[i][j] = INT_MAX;
        }
        f[i][i] = 0;
    }

//    cout << "f: \n";
//
//    for (int i = 1; i <= n; ++i) {
//        for (int j = 1; j <= n; ++j) {
//            cout << f[i][j] << ' ';
//        }
//        cout << '\n';
//    }


    for (int i = 1; i <= m; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        u[i] = x, v[i] = y, wt[i] = z;
        f[x][y] = f[y][x] = z;
    }

//    cout << "f: \n";
//
//    for (int i = 1; i <= n; ++i) {
//        for (int j = 1; j <= n; ++j) {
//            cout << f[i][j] << ' ';
//        }
//        cout << '\n';
//    }

    // floyd shortest path
    for (int k = 1; k <= n; ++k) {
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                if (f[i][k] != INT_MAX && f[k][j] != INT_MAX) {
                    f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
                }
            }
        }
    }

//    cout << "f: \n";
//
//    for (int i = 1; i <= n; ++i) {
//        for (int j = 1; j <= n; ++j) {
//            cout << f[i][j] << ' ';
//        }
//        cout << '\n';
//    }

    int ans = 0;
    for (int i = 1; i <= m; ++i) {
//        cout << "Now is at edge " << i << " with weight " << wt[i] << '\n';
//        cout << "u: " << u[i] << ", v: " << v[i] << '\n';
//        cout << "positive: " << f[s][u[i]] << ", " << f[v[i]][t] << '\n';
//        cout << "negative: " << f[s][v[i]] << ", " << f[u[i]][t] << '\n';
        if (min(f[s][u[i]] + wt[i] +  f[v[i]][t], f[s][v[i]] + wt[i] + f[u[i]][t]) != f[s][t]) {
//            cout << "i: " << i << '\n';
            ans += wt[i];
        }
    }



    cout << ans << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3676kb

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

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

input:

2 1 1 2
1 2 10

output:

0

result:

ok single line: '0'

Test #4:

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

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

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

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

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

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

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

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

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

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

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

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: 2ms
memory: 3772kb

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

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

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

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

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

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

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

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'