結果

問題 No.160 最短経路のうち辞書順最小
ユーザー kuuso1kuuso1
提出日時 2015-03-08 01:12:21
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 129 ms / 5,000 ms
コード長 1,703 bytes
コンパイル時間 5,400 ms
コンパイル使用メモリ 107,204 KB
実行使用メモリ 26,976 KB
最終ジャッジ日時 2023-09-06 21:02:39
合計ジャッジ時間 7,285 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
22,800 KB
testcase_01 AC 61 ms
20,772 KB
testcase_02 AC 61 ms
22,784 KB
testcase_03 AC 61 ms
22,808 KB
testcase_04 AC 111 ms
22,828 KB
testcase_05 AC 116 ms
24,948 KB
testcase_06 AC 120 ms
24,808 KB
testcase_07 AC 110 ms
20,776 KB
testcase_08 AC 110 ms
22,812 KB
testcase_09 AC 110 ms
20,824 KB
testcase_10 AC 110 ms
20,820 KB
testcase_11 AC 110 ms
20,812 KB
testcase_12 AC 109 ms
20,712 KB
testcase_13 AC 109 ms
22,816 KB
testcase_14 AC 111 ms
22,800 KB
testcase_15 AC 109 ms
20,684 KB
testcase_16 AC 109 ms
20,676 KB
testcase_17 AC 110 ms
20,708 KB
testcase_18 AC 110 ms
20,864 KB
testcase_19 AC 109 ms
20,696 KB
testcase_20 AC 110 ms
22,752 KB
testcase_21 AC 110 ms
20,872 KB
testcase_22 AC 109 ms
20,724 KB
testcase_23 AC 111 ms
22,696 KB
testcase_24 AC 110 ms
20,760 KB
testcase_25 AC 109 ms
20,692 KB
testcase_26 AC 109 ms
22,804 KB
testcase_27 AC 108 ms
20,676 KB
testcase_28 AC 129 ms
26,976 KB
testcase_29 AC 108 ms
20,824 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
 
class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int Inf=(int)(1e9);
		bool[,] canGo=new bool[N,N];
		int[,] dist=new int[N,N];
		
		int[][] WF=new int[N][];
		for(int i=0;i<N;i++){
			WF[i]=new int[N];
			for(int j=0;j<N;j++)WF[i][j]=(i==j)?0:Inf;
		}
		
		
		
		for(int i=0;i<M;i++){
			var dd=ria();
			WF[dd[0]][dd[1]]=WF[dd[1]][dd[0]]=dd[2];
			canGo[dd[0],dd[1]]=canGo[dd[1],dd[0]]=true;
			dist[dd[0],dd[1]]=dist[dd[1],dd[0]]=dd[2];
		}
		
		for(int k=0;k<N;k++){
			for(int i=0;i<N;i++){
				for(int j=0;j<N;j++){
					WF[i][j]=Math.Min(WF[i][j],WF[i][k]+WF[k][j]);
				}
			}
		}
		
		List<int> L=new List<int>();
		int now=S;
		while(now!=G){
			L.Add(now);
			for(int i=0;i<N;i++){
				if(!canGo[now,i])continue;
				if(WF[now][G]==WF[i][G]+dist[now,i]){
					now=i;
					break;
				}
			}
		}
		L.Add(now);
		
		var AA=L.ToArray();
		Console.WriteLine(String.Join(" ",AA));
		
	}
	int N,M;
	int S,G;
	
	public Sol(){
		var d=ria();
		N=d[0];M=d[1];S=d[2];G=d[3];
	}

	


	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}
0