結果

問題 No.160 最短経路のうち辞書順最小
ユーザー kuuso1kuuso1
提出日時 2015-03-08 01:03:08
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,816 bytes
コンパイル時間 3,535 ms
コンパイル使用メモリ 111,188 KB
実行使用メモリ 24,940 KB
最終ジャッジ日時 2023-09-06 21:00:15
合計ジャッジ時間 7,546 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
20,824 KB
testcase_01 AC 53 ms
20,860 KB
testcase_02 AC 53 ms
18,704 KB
testcase_03 WA -
testcase_04 AC 97 ms
22,820 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 AC 91 ms
20,788 KB
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 AC 105 ms
20,664 KB
testcase_28 AC 123 ms
24,896 KB
testcase_29 AC 104 ms
22,832 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[][] 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;
		}
		
		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]+WF[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));}
}

class Pair : IComparable<Pair> {
	public int Pos;
	public int Cost;
	public Pair(int p, int c) {
		Pos = p; Cost = c;
	}
	public int CompareTo(Pair t) {
		//return this.Cost > t.Cost ? -1 : this.Cost < t.Cost ? 1 : 0;
		return this.Cost > t.Cost ? 1 : this.Cost < t.Cost ? -1 : 0;
	}
}


class SkewHeap<T> where T:IComparable<T>{
	public int Count{
		get{return cnt;}
		private set{cnt=value;}
	}
	
	public SkewHeap(){
		root=null;
		this.Count=0;
	}
	
	public void Push(T v){
		NodeSH<T> p=new NodeSH<T>(v);
		root=NodeSH<T>.Meld(root,p);
		this.Count++;
	}
	
	public void Pop(){
		if(root==null)return;
		root=NodeSH<T>.Meld(root.L,root.R);
		this.Count--;
	}
	
	public T Top{
		get{return root.Val;}
	}
	
	int cnt;
	NodeSH<T> root;
	
	class NodeSH<S> where S : IComparable<S> {
		public NodeSH<S> L, R;
		public S Val;

		public NodeSH(S v){
			Val = v;
			L = null; R = null;
		}
		public static NodeSH<S> Meld(NodeSH<S> a, NodeSH<S> b){
			if(a == null)return b;
			if (b == null) return a;
			if (a.Val.CompareTo(b.Val) > 0) swap(ref a, ref b);
			a.R = Meld(a.R, b);
			swap(ref a.L, ref a.R);
			return a;
		}

		static void swap<U>(ref U x, ref U y) {
			U t = x; x = y; y = t;
		}
	}
}
0