結果

問題 No.807 umg tours
ユーザー Tomohiko HasegawaTomohiko Hasegawa
提出日時 2019-04-03 16:07:25
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,591 bytes
コンパイル時間 1,578 ms
コンパイル使用メモリ 65,736 KB
実行使用メモリ 507,488 KB
最終ジャッジ日時 2023-08-23 11:37:03
合計ジャッジ時間 25,769 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
27,232 KB
testcase_01 AC 62 ms
20,620 KB
testcase_02 AC 64 ms
20,696 KB
testcase_03 AC 63 ms
20,744 KB
testcase_04 AC 61 ms
20,640 KB
testcase_05 AC 63 ms
20,760 KB
testcase_06 AC 64 ms
20,716 KB
testcase_07 AC 62 ms
20,704 KB
testcase_08 AC 60 ms
20,848 KB
testcase_09 AC 62 ms
22,688 KB
testcase_10 AC 62 ms
20,796 KB
testcase_11 AC 3,272 ms
381,744 KB
testcase_12 AC 1,967 ms
279,172 KB
testcase_13 AC 2,163 ms
246,728 KB
testcase_14 AC 896 ms
127,848 KB
testcase_15 AC 1,010 ms
141,372 KB
testcase_16 AC 2,892 ms
279,608 KB
testcase_17 AC 3,254 ms
300,500 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.yukicoder
{
    class _807
    {
        static void Main(string[] args)
        {
            Method(args);
            ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nm = ReadInts();
            int n = nm[0];
            int m = nm[1];
            List<int[]>[] graph = new List<int[]>[n];
            for (int i = 0; i < n; i++) graph[i] = new List<int[]>();
            for(int i = 0; i < m; i++)
            {
                int[] abc = ReadInts();
                int a = abc[0] - 1;
                int b = abc[1] - 1;
                int c = abc[2];
                graph[a].Add(new int[2] { b, c });
                graph[b].Add(new int[2] { a, c });
            }
            long[,] dists = new long[n, 2];
            for(int i = 0; i < n; i++)
            {
                dists[i, 0] = long.MaxValue/8;
                dists[i, 1] = long.MaxValue/8;
            }
            Queue<long[]> queue = new Queue<long[]>();
            queue.Enqueue(new long[3] { 0, 0, 0 });
            while (queue.Count > 0)
            {
                long[] val = queue.Dequeue();
                if (dists[val[0], val[1]] <= val[2]) continue;

                dists[val[0], val[1]] = val[2];

                for(int i = 0; i < graph[val[0]].Count; i++)
                {
                    int[] to = graph[val[0]][i];
                    queue.Enqueue(
                        new long[3] { to[0], val[1], val[2] + to[1] });
                    if (val[1] == 0)
                    {
                        queue.Enqueue(
                            new long[3] { to[0], 1, val[2] });
                    }
                }
            }
            WriteLine(0);
            for(int i = 1; i < n; i++)
            {
                WriteLine(dists[i, 0] + dists[i, 1]);
            }
        }

        private static string Read() { return ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}
0