wenbao与hiho最短路还原
http://hihocoder.com/problemset/problem/1379
1 #include <iostream> 2 #include <stdio.h> 3 using namespace std; 4 int a[305][305], mark[305][305]; 5 int main(){ 6 int n, num = 0; 7 scanf("%d", &n); 8 for(int i = 1; i <= n; i++){ 9 for(int j = 1; j <= n; j++){ 10 scanf("%d", &a[i][j]); 11 } 12 } 13 for(int i = 1; i <= n; i++){ 14 for(int j = i+1; j <=n; j++){ 15 for(int k = 1; k <= n; k++){ 16 if(k != i && k != j && !mark[i][j] && a[i][k]+a[k][j] == a[i][j]){ 17 // cout<<i<<"------"<<j<<endl; 18 mark[i][j] = mark[j][i] = 1; 19 num++; 20 } 21 } 22 } 23 } 24 // cout<<num<<endl; 25 printf("%d\n", (n*(n-1))/2 - num); 26 return 0; 27 }
只有不断学习才能进步!