結果

問題 No.845 最長の切符
ユーザー ohreitetsuohreitetsu
提出日時 2019-07-03 22:09:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 884 bytes
コンパイル時間 699 ms
コンパイル使用メモリ 75,004 KB
実行使用メモリ 5,292 KB
最終ジャッジ日時 2023-10-14 22:28:05
合計ジャッジ時間 2,471 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,356 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 1 ms
4,356 KB
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 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
				}
				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;
		C1[b-1][a-1]=c;
	}
	int MaxD=getDist(C1);
	cout<<MaxD<<endl;

	return 0;
}
0