aboutsummaryrefslogtreecommitdiff
path: root/rcc-legacy/tests/sysy_lvX/floyd.sy
blob: f2aad9c6d8ec97a2a5817fcbdc9a3ac3a7dec272 (plain)
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
const int N = 1024;
int dist[N][N];

int main() {
    int n = getint();
    int i, j;
    i = 0;
    while (i < n) {
        j = 0;
        while (j < n) {
            dist[i][j] = getint();
            j = j + 1;
        }
        i = i + 1;
    }

    starttime();

    int k = 0;
    while (k < n) {
        i = 0;
        while (i < n) {
            j = 0;
            while (j < n) {
                if (dist[i][k] + dist[k][j] < dist[i][j]) {
                    dist[i][j] = dist[i][k] + dist[k][j];
                }
                j = j + 1;
            }
            i = i + 1;
        }
        k = k + 1;
    }


    stoptime();
    i = 0;
    while (i < n) {
        j = 0;
        while (j < n) {
            putint(dist[i][j]);
            putch(32);
            j = j + 1;
        }
        i = i + 1;
    }
}