結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー kuuso1kuuso1
提出日時 2016-12-10 03:01:21
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 854 ms / 2,000 ms
コード長 2,365 bytes
コンパイル時間 4,355 ms
コンパイル使用メモリ 104,068 KB
実行使用メモリ 67,764 KB
最終ジャッジ日時 2023-08-20 02:17:35
合計ジャッジ時間 16,898 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
22,008 KB
testcase_01 AC 67 ms
21,844 KB
testcase_02 AC 66 ms
23,708 KB
testcase_03 AC 68 ms
21,604 KB
testcase_04 AC 68 ms
21,700 KB
testcase_05 AC 69 ms
23,768 KB
testcase_06 AC 69 ms
21,832 KB
testcase_07 AC 68 ms
21,760 KB
testcase_08 AC 69 ms
23,820 KB
testcase_09 AC 70 ms
24,060 KB
testcase_10 AC 66 ms
23,732 KB
testcase_11 AC 65 ms
21,692 KB
testcase_12 AC 64 ms
19,668 KB
testcase_13 AC 65 ms
23,892 KB
testcase_14 AC 69 ms
23,828 KB
testcase_15 AC 70 ms
23,940 KB
testcase_16 AC 70 ms
23,784 KB
testcase_17 AC 71 ms
23,732 KB
testcase_18 AC 71 ms
21,736 KB
testcase_19 AC 71 ms
21,744 KB
testcase_20 AC 71 ms
23,772 KB
testcase_21 AC 71 ms
21,716 KB
testcase_22 AC 70 ms
19,968 KB
testcase_23 AC 71 ms
21,728 KB
testcase_24 AC 818 ms
67,692 KB
testcase_25 AC 851 ms
65,816 KB
testcase_26 AC 854 ms
63,544 KB
testcase_27 AC 842 ms
63,624 KB
testcase_28 AC 757 ms
65,556 KB
testcase_29 AC 751 ms
65,560 KB
testcase_30 AC 759 ms
67,764 KB
testcase_31 AC 771 ms
67,664 KB
testcase_32 AC 823 ms
67,628 KB
testcase_33 AC 842 ms
67,580 KB
testcase_34 AC 281 ms
56,496 KB
testcase_35 AC 67 ms
21,684 KB
testcase_36 AC 66 ms
21,660 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;
using System.Linq;
using System.Text;
using System.Diagnostics;

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

class Sol{
	public void Solve(){
		
		int[] InDeg = new int[N];
		for(int i=0;i<N;i++){
			foreach(var nxt in E[i]) InDeg[nxt.Pos]++;
		}
		
//		Debug.Assert( InDeg[0] == 0 );
//		Debug.Assert( InDeg.Skip(1).Select(x => x !=0).Aggregate(true, (b,y) => b&y ) );
		
		int[] ENT = new int[N];	// Earliest Node Time
		for(int i=0;i<N;i++) ENT[i] = -1;
		ENT[0] = 0;
		
		Queue<int> Q = new Queue<int>();
		Q.Enqueue(0);
		while(Q.Count>0){
			var now = Q.Dequeue();
			foreach(var nxt in E[now]){
				InDeg[nxt.Pos]--;
				if(InDeg[nxt.Pos] == 0){
					Q.Enqueue(nxt.Pos);
				}
				ENT[nxt.Pos] = Math.Max(ENT[nxt.Pos], ENT[now] + nxt.Cost);
			}
		}
		
		int[] OutDeg = new int[N];
		
		int[] LNT = new int[N]; // Latest Node Time
		for(int i=0;i<N;i++) LNT[i] = int.MaxValue;
		LNT[N-1] = ENT[N-1];
		
		Q = new Queue<int>();
		Q.Enqueue(N-1);
		while(Q.Count>0){
			var now = Q.Dequeue();
			foreach(var rev in XE[now]){
				OutDeg[rev.Pos]++;
				if(OutDeg[rev.Pos] == E[rev.Pos].Count){
					Q.Enqueue(rev.Pos);
				}
				LNT[rev.Pos] = Math.Min(LNT[rev.Pos], LNT[now] - rev.Cost);
			}
		}
		
//		Debug.Assert( OutDeg[N-1] == 0 );
//		Debug.Assert( OutDeg.Zip(E,(n,p) => n == p.Count).Aggregate(true, (b,y) => b&y ) );
//		Debug.Assert( ENT.Zip(LNT,(e,l) => e > l).Count( b => b ) == 0);
		
		//Console.WriteLine(String.Join(" ",ENT));
		//Console.WriteLine(String.Join(" ",LNT));
		
		int marginPersonCount = ENT.Zip(LNT,(e,l) => l > e).Count( b => b );
		Console.WriteLine("{0} {1}/{2}",ENT[N-1],marginPersonCount,N);
		
	}
	
	int N,M;
	List<Pair>[] E;
	List<Pair>[] XE;
	
	public Sol(){
		// read input
		int[] d;
		d = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
		N = d[0]; M = d[1];
		
		E = new List<Pair>[N];
		for(int i=0;i<N;i++) E[i] = new List<Pair>();
		XE = new List<Pair>[N];
		for(int i=0;i<N;i++) XE[i] = new List<Pair>();
		
		for(int i=0;i<M;i++){
			d = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
			E[d[0]].Add(new Pair(d[1],d[2]));
			XE[d[1]].Add(new Pair(d[0],d[2]));
		}
	}
	
	class  Pair{
		public int Pos,Cost;
		public Pair(int pos, int cost){
			Pos = pos; Cost = cost;
		}
	}
	
}
0