結果
| 問題 |
No.468 役に立つ競技プログラミング実践編
|
| ユーザー |
kuuso1
|
| 提出日時 | 2016-12-10 03:18:57 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,461 bytes |
| コンパイル時間 | 1,090 ms |
| コンパイル使用メモリ | 113,772 KB |
| 実行使用メモリ | 74,164 KB |
| 最終ジャッジ日時 | 2024-11-30 01:34:18 |
| 合計ジャッジ時間 | 12,409 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 31 |
| other | WA * 6 |
コンパイルメッセージ
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;
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 );
int marginPersonCount = 0;
for(int i=0;i<N;i++) if(ENT[i] == LNT[i]) marginPersonCount++;
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;
}
}
}
kuuso1