結果

問題 No.1601 With Animals into Institute
ユーザー laneguelanegue
提出日時 2021-07-14 12:36:41
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 1,578 ms / 3,000 ms
コード長 1,330 bytes
コンパイル時間 2,297 ms
コンパイル使用メモリ 159,104 KB
実行使用メモリ 60,436 KB
最終ジャッジ日時 2023-09-04 13:12:21
合計ジャッジ時間 24,160 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 27 ms
6,516 KB
testcase_04 AC 28 ms
4,980 KB
testcase_05 AC 27 ms
4,716 KB
testcase_06 AC 1,517 ms
59,012 KB
testcase_07 AC 1,534 ms
59,096 KB
testcase_08 AC 1,549 ms
59,564 KB
testcase_09 AC 1,578 ms
59,960 KB
testcase_10 AC 1,561 ms
59,856 KB
testcase_11 AC 1,566 ms
60,436 KB
testcase_12 AC 1,569 ms
60,088 KB
testcase_13 AC 1,573 ms
60,284 KB
testcase_14 AC 1,561 ms
59,648 KB
testcase_15 AC 1,550 ms
60,268 KB
testcase_16 AC 1,544 ms
59,928 KB
testcase_17 AC 1,554 ms
59,272 KB
testcase_18 AC 25 ms
4,924 KB
testcase_19 AC 27 ms
5,092 KB
testcase_20 AC 27 ms
5,056 KB
testcase_21 AC 27 ms
5,072 KB
testcase_22 AC 26 ms
4,920 KB
testcase_23 AC 27 ms
4,992 KB
testcase_24 AC 27 ms
5,104 KB
testcase_25 AC 28 ms
4,972 KB
testcase_26 AC 26 ms
4,948 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 2 ms
4,384 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio;
import std.array;
import std.conv;
import std.container;
import std.math;

struct Edge{
	int to;
	long weight;
	bool animal;
}

void main(){
	auto l = readln.split.to!(int[]);
	auto n = l[0];
	auto m = l[1];
	auto e = new Edge[][n];
	for(auto i = 0; i < m; i++){
		l = readln.split.to!(int[]);
		auto a = l[0] - 1;
		auto b = l[1] - 1;
		auto c = l[2];
		auto x = (l[3] == 1);
		auto edge = Edge(b, c, x);
		e[a] ~= edge;
		edge = Edge(a, c, x);
		e[b] ~= edge;
	}
	auto distance = new long[n];
	distance[] = long.max;
	auto pq = new BinaryHeap!(Array!Edge, (a, b) => (a.weight > b.weight));
	auto edge = Edge(n - 1, 0, false);
	pq.insert(edge);
	while(!pq.empty){
		edge = pq.front;
		pq.removeFront;
		if(edge.animal){
			if(edge.weight < distance[edge.to]){
				distance[edge.to] = edge.weight;
			}else{
				continue;
			}
		}else{
			if(edge.weight < distance[edge.to] - 10L ^^ 15){
				distance[edge.to] = edge.weight + 10L ^^ 15;
			}else{
				continue;
			}
		}
		foreach(c; e[edge.to]){
			auto d = Edge(c.to, edge.weight + c.weight, edge.animal || c.animal);
			pq.insert(d);
			if(!edge.animal && c.animal){
				d = Edge(c.to, edge.weight + c.weight * 2, edge.animal || c.animal);
				pq.insert(d);
			}
		}
	}
	stderr.writeln(distance);
	for(auto i = 0; i < n - 1; i++){
		distance[i].writeln;
	}
}

0