結果
問題 |
No.160 最短経路のうち辞書順最小
|
ユーザー |
![]() |
提出日時 | 2015-03-08 01:12:21 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 97 ms / 5,000 ms |
コード長 | 1,703 bytes |
コンパイル時間 | 915 ms |
コンパイル使用メモリ | 112,228 KB |
実行使用メモリ | 30,408 KB |
最終ジャッジ日時 | 2024-06-24 15:22:50 |
合計ジャッジ時間 | 4,125 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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));} }