結果
| 問題 |
No.1601 With Animals into Institute
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-14 12:36:41 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 1,335 ms / 3,000 ms |
| コード長 | 1,330 bytes |
| コンパイル時間 | 1,957 ms |
| コンパイル使用メモリ | 163,424 KB |
| 実行使用メモリ | 60,272 KB |
| 最終ジャッジ日時 | 2024-06-22 11:43:49 |
| 合計ジャッジ時間 | 19,361 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
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;
}
}