-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSPOJ-ROHAAN.cpp
More file actions
50 lines (40 loc) · 788 Bytes
/
SPOJ-ROHAAN.cpp
File metadata and controls
50 lines (40 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <bits/stdc++.h>
#define INF 1e8
#define MAX 300
using namespace std;
int matriz[MAX][MAX];
int D[MAX][MAX];
void fw(int n){
for (int k = 0; k < n; k++){
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
if (matriz[i][j] > matriz[i][k] + matriz[k][j])
matriz[i][j] = matriz[i][k] + matriz[k][j];
}
}
}
}
int main (){
ios::sync_with_stdio(0); cin.tie(nullptr);
int t, n, r, soma;
cin >> t;
for(int i = 0; i < t; i++){
soma = 0;
cin >> n;
for(int j = 0; j < n; j++){
for(int k = 0; k < n; k++){
int temp;
cin >> matriz[j][k];
}
}
fw(n);
cin >> r;
for(int j = 0; j < r; j++){
int t1, t2;
cin >> t1 >> t2;
soma += matriz[t1-1][t2-1];
}
cout << "Case #" << i+1 << ": " << soma << endl;
}
return 0;
}