Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
150110 | 梁乃元 | 最短路径 | C++ | 解答错误 | 90 | 0 MS | 248 KB | 804 | 2024-06-01 15:36:36 |
# include <bits/stdc++.h> using namespace std ; int n , i , j ; int a [105] [105] , f [105] , c [105] ; int main ( ) { cin >> n ; memset ( f , 0 , sizeof ( f ) ) ; memset ( c , 0 , sizeof ( c ) ) ; for ( i = 1 ; i <= n + 1 ; i ++ ) { for ( j = 1 ; j <= n + 1 ; j ++ ) { a [i] [j] = -1 ; } } int o = 1 , t = 1 , th = 1 ; while ( o != 0 && t != 0 && th != 0 ) { cin >> o >> t >> th ; a [o] [t] = th ; } for ( int i = 1 ; i < n ; i ++ ) { f [i] = 0x7fffffff ; } f [n] = 0 ; for ( i = n - 1 ; i >= 1 ; i -- ) { for ( j = n ; j > i ; j -- ) { if ( ( a [i] [j] > 0 ) && ( f [j] != 0x7fffffff ) && ( f [j] + a [i] [j] < f [i] ) ) { f [i] = f [j] + a [i] [j] ; c [i] = j ; } } } cout << f [1] << endl ; return 0 ; }