結果

問題 No.30 たこやき工場
ユーザー nanophoto12
提出日時 2014-11-02 22:41:12
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 2,326 bytes
コンパイル時間 1,508 ms
コンパイル使用メモリ 107,904 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-12-30 16:24:58
合計ジャッジ時間 3,048 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other RE * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

public class Program
{
    private class Source
    {
        private readonly int _id;
        private readonly uint _count;

        public Source(int id, uint count)
        {
            _id = id;
            _count = count;
        }

        public int Id
        {
            get { return _id; }
        }

        public uint Count
        {
            get { return _count; }
        }

        public Source Mul(uint count)
        {
            return new Source(_id, _count * count);
        }
    }

    private static Source[] Dfs(List<Source>[] sourceList, Source[][] memo, int id, bool[] used)
    {
        if (sourceList[id].Count == 0)
        {
            return new[]{ new Source(id, 1)};
        }
        if (!used[id])
        {
            var sources = new List<Source>();
            for(int k = 0;k < sourceList[id].Count;k++)
            {
                Source source = sources[k];
                uint sourceCount = source.Count;
                var result = Dfs(sourceList, memo, source.Id, used);
                for (int i = 0; i < result.Length;i++)
                {
                    sources.Add(result[i].Mul(sourceCount));
                }
            }
            used[id] = true;
            memo[id] = sources.ToArray();
        }
        return memo[id];
    }

    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int m = int.Parse(Console.ReadLine());
        List<Source>[] list = new List<Source>[n + 1];
        for (int i = 0; i < n + 1; i++)
        {
            list[i] = new List<Source>();
        }
        for (int i = 0; i < m; i++)
        {
            var line = Console.ReadLine().Split(' ').Select(element => int.Parse(element)).ToArray();
            list[line[2]].Add(new Source(line[0], (uint)line[1]));
        }
        bool[] used = new bool[n + 1];
        var result = Dfs(list, new Source[n+1][],  n, used);
        uint[] count = new uint[n+1];
        foreach (var element in result)
        {
            count[element.Id] += element.Count;
        }
        for (int i = 1; i < n; i++)
        {
            Console.WriteLine(count[i]);
        }
    }
}
0