結果

問題 No.845 最長の切符
ユーザー ohreitetsuohreitetsu
提出日時 2019-07-03 22:19:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 996 bytes
コンパイル時間 934 ms
コンパイル使用メモリ 76,324 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-10-14 22:37:34
合計ジャッジ時間 2,273 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 1 ms
4,352 KB
testcase_26 AC 2 ms
4,352 KB
testcase_27 AC 1 ms
4,352 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N,M;
int getDist(vector<vector<int>> C) 
{ 
	int MaxD=0;
	bool loop=true;
	while (loop){
		loop =false;
		for (int i = 0; i < N; i++){      // 経由する頂点
			for (int j = 0; j < N; j++){    // 開始頂点
				if (i==j){
					continue;
				}
				if (MaxD<C[i][j]){
					MaxD=C[i][j];
				}
				for (int k = 0; k < N; k++){  // 終端
					if (i==k || j==k){
						continue;
					}
					if (C[j][k]==0){
						if (C[j][i]>0 && C[i][k]>0){
							C[j][k] = C[j][i] + C[i][k];
							if (MaxD<C[j][k]){
								MaxD=C[j][k];
								loop=true;
							}
						}

					}
				}
			}
		}
	}
	return MaxD;
}

int main(int argc, char* argv[])
{
	int i;
	cin>>N>>M;
	vector<vector<int>> C1(N,vector<int>(N));
	int a,b,c;
	for (i=0;i<M;i++){
		cin>>a>>b>>c;
		C1[a-1][b-1]=c;
	}
	for (i=0;i<M;i++){
		if (C1[b-1][a-1]==0){
			C1[b-1][a-1]=	C1[a-1][b-1];
		}
	}
	int MaxD=getDist(C1);
	cout<<MaxD<<endl;

	return 0;
}
0