QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#325117 | #5613. Road To Savings | weilaifuture# | AC ✓ | 2ms | 3904kb | C++14 | 1.2kb | 2024-02-11 04:22:52 | 2024-02-11 04:22:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 105;
const int INF = 100000000;
int n,m,a,b,d[N],e[N][N],w[N][N],ans,vst[N],ok[N];
vector<int> tmp[N];
void dijkstra(){
for(int i=0;i<=n;i++) d[i]=INF; d[a]=0;
for(int c=1;c<=n;c++){
int v=0; for(int i=1;i<=n;i++) if(!ok[i]&&d[i]<d[v]) v=i;
ok[v]=1;
for(int u = 1; u <= n; u++){
if(!e[v][u]) continue;
if(d[u]>d[v] + w[v][u]) d[u] = d[v] + w[v][u], tmp[u].clear(), tmp[u].push_back(v);
else if(d[u] == d[v] + w[v][u]) tmp[u].push_back(v);
}
}
}
void bfs(){
queue<int> q; q.push(b);
while(!q.empty()){
int nw = q.front(); q.pop();
for(int i=0;i<tmp[nw].size();i++){
int l = tmp[nw][i];
ans -= w[l][nw];
if(vst[l]) continue;
q.push(l); vst[l]=1;
}
}
}
int main(){
cin>>n>>m>>a>>b;
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) w[i][j] = INF;
while(m--){
int h1,h2,h3;
cin>>h1>>h2>>h3;
w[h1][h2] = h3; w[h2][h1] = h3;
e[h1][h2] = 1; e[h2][h1] = 1;
ans+=h3;
}
dijkstra(); bfs();
cout<<ans;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3492kb
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: 3620kb
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: 1ms
memory: 3760kb
input:
2 1 1 2 1 2 10
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3516kb
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: 1ms
memory: 3492kb
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: 2ms
memory: 3664kb
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: 3620kb
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: 3584kb
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: 3556kb
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: 3808kb
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: 3528kb
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: 3876kb
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: 2ms
memory: 3652kb
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: 3656kb
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: 3904kb
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: 2ms
memory: 3848kb
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: 3544kb
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: 3624kb
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: 3672kb
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: 2ms
memory: 3652kb
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: 3548kb
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: 2ms
memory: 3816kb
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: 3492kb
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: 3560kb
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: 3580kb
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'