結果

問題 No.17 2つの地点に泊まりたい
ユーザー skewesskewes
提出日時 2015-12-30 15:33:21
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 61 ms / 5,000 ms
コード長 2,160 bytes
コンパイル時間 3,817 ms
コンパイル使用メモリ 102,036 KB
実行使用メモリ 22,784 KB
最終ジャッジ日時 2023-08-05 03:41:11
合計ジャッジ時間 5,015 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
22,680 KB
testcase_01 AC 58 ms
20,736 KB
testcase_02 AC 58 ms
22,768 KB
testcase_03 AC 58 ms
20,760 KB
testcase_04 AC 59 ms
22,740 KB
testcase_05 AC 60 ms
20,724 KB
testcase_06 AC 58 ms
20,640 KB
testcase_07 AC 59 ms
22,716 KB
testcase_08 AC 60 ms
20,824 KB
testcase_09 AC 60 ms
20,708 KB
testcase_10 AC 59 ms
20,724 KB
testcase_11 AC 60 ms
20,664 KB
testcase_12 AC 58 ms
20,820 KB
testcase_13 AC 57 ms
18,748 KB
testcase_14 AC 58 ms
22,720 KB
testcase_15 AC 58 ms
22,748 KB
testcase_16 AC 57 ms
20,816 KB
testcase_17 AC 58 ms
20,632 KB
testcase_18 AC 59 ms
18,860 KB
testcase_19 AC 58 ms
22,784 KB
testcase_20 AC 58 ms
22,672 KB
testcase_21 AC 58 ms
20,780 KB
testcase_22 AC 59 ms
20,784 KB
testcase_23 AC 61 ms
22,688 KB
testcase_24 AC 60 ms
20,660 KB
testcase_25 AC 57 ms
20,768 KB
testcase_26 AC 60 ms
20,696 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

namespace yukicoder
{
    class _061
    {
        static int n;
        static int[,] en;
        static void Main()
        {
            n = int.Parse(Console.ReadLine());
            en = new int[n, n];
            int[] sn = new int[n];
            for (int i = 0; i < n; i++)
            {
                sn[i] = int.Parse(Console.ReadLine());
            }

            int m = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (i != j) en[i, j] = int.MaxValue;
                }
            }
            for (int i = 0; i < m; i++)
            {
                int[] abc = Array.ConvertAll(Console.ReadLine().Split(' ')
                   , x => int.Parse(x));
                en[abc[0], abc[1]] = abc[2];
                en[abc[1], abc[0]] = abc[2];
            }

            wf();

            int min = int.MaxValue;
            for (int i = 1; i < n - 1; i++)
            {
                if (en[0, i] == int.MaxValue) continue;
                for (int j = 1; j < n - 1; j++)
                {
                    if (en[j, n - 1] == int.MaxValue) continue;
                    if (en[i, j] == int.MaxValue) continue;
                    if (i == j) continue;
                    min = Math.Min(min,
                        en[0, i] + en[i, j] + en[j, n - 1] + sn[i] + sn[j]);
                }
            }
            Console.WriteLine(min);
        }

        static void wf()
        {
            for (int k = 0; k < n; k++)
            {
                for (int i = 0; i < n; i++)
                {
                    if (en[i, k] == int.MaxValue) continue;
                    for (int j = 0; j < n; j++)
                    {
                        if (en[k, j] == int.MaxValue) continue;
                        int pk = en[i, k] + en[k, j];
                        if (en[i, j] > pk)
                        {
                            en[i, j] = pk;
                            en[j, i] = pk;
                        }
                    }
                }
            }
        }
    }
}
0