結果

問題 No.807 umg tours
ユーザー Tomohiko Hasegawa
提出日時 2019-04-03 16:07:25
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,591 bytes
コンパイル時間 1,254 ms
コンパイル使用メモリ 111,092 KB
実行使用メモリ 824,704 KB
最終ジャッジ日時 2024-12-21 14:10:11
合計ジャッジ時間 30,803 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23 TLE * 1 MLE * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
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