結果

問題 No.1320 Two Type Min Cost Cycle
ユーザー さかぽんさかぽん
提出日時 2020-12-25 23:40:15
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,282 bytes
コンパイル時間 874 ms
コンパイル使用メモリ 112,000 KB
実行使用メモリ 24,416 KB
最終ジャッジ日時 2023-10-24 00:05:53
合計ジャッジ時間 5,142 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
24,212 KB
testcase_01 WA -
testcase_02 AC 26 ms
24,216 KB
testcase_03 AC 26 ms
24,212 KB
testcase_04 WA -
testcase_05 AC 26 ms
24,204 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 28 ms
24,208 KB
testcase_09 AC 30 ms
24,232 KB
testcase_10 WA -
testcase_11 AC 30 ms
24,232 KB
testcase_12 AC 29 ms
24,204 KB
testcase_13 AC 30 ms
24,208 KB
testcase_14 AC 27 ms
24,212 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 28 ms
24,212 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 27 ms
24,216 KB
testcase_28 AC 28 ms
24,212 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 30 ms
24,416 KB
testcase_34 AC 29 ms
24,340 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 27 ms
24,212 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 29 ms
24,208 KB
testcase_46 WA -
testcase_47 AC 29 ms
24,388 KB
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 27 ms
24,212 KB
testcase_51 AC 27 ms
24,212 KB
testcase_52 AC 28 ms
24,212 KB
testcase_53 AC 28 ms
24,236 KB
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Generic;

class Q
{
	static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
	static (int, int) Read2() { var a = Read(); return (a[0], a[1]); }
	static void Main()
	{
		var directed = int.Parse(Console.ReadLine()) == 1;
		var (n, m) = Read2();
		var es = Array.ConvertAll(new bool[m], _ => Read());
		var map = EdgesToMap2(n + 1, es, directed);

		var r = long.MaxValue;
		var u = new bool[n + 1];
		var costs = new long[n + 1];

		if (directed)
		{

		}
		else
		{
			for (int v = 1; v <= n; v++)
			{
				if (u[v]) continue;
				DfsU(v, -1);
			}
			Console.WriteLine(r == long.MaxValue ? -1 : r);
		}

		void DfsU(int v, int pv)
		{
			u[v] = true;
			foreach (var e in map[v])
			{
				var nv = e[1];
				if (nv == pv) continue;
				if (u[nv])
				{
					if (costs[v] > costs[nv])
						r = Math.Min(r, costs[v] - costs[nv] + e[2]);
					continue;
				}

				costs[nv] = costs[v] + e[2];
				DfsU(nv, v);
			}
		}
	}

	static List<int[]>[] EdgesToMap2(int n, int[][] es, bool directed)
	{
		var map = Array.ConvertAll(new bool[n], _ => new List<int[]>());
		foreach (var e in es)
		{
			map[e[0]].Add(new[] { e[0], e[1], e[2] });
			if (!directed) map[e[1]].Add(new[] { e[1], e[0], e[2] });
		}
		return map;
	}
}
0