結果

問題 No.806 木を道に
ユーザー to_to_0121to_to_0121
提出日時 2019-03-22 22:19:08
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 2,610 bytes
コンパイル時間 3,870 ms
コンパイル使用メモリ 110,304 KB
実行使用メモリ 46,576 KB
最終ジャッジ日時 2023-10-19 09:37:14
合計ジャッジ時間 4,719 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
24,152 KB
testcase_01 AC 26 ms
24,152 KB
testcase_02 AC 27 ms
24,156 KB
testcase_03 AC 27 ms
24,156 KB
testcase_04 AC 26 ms
24,156 KB
testcase_05 AC 27 ms
24,156 KB
testcase_06 AC 26 ms
24,156 KB
testcase_07 AC 26 ms
24,156 KB
testcase_08 AC 27 ms
24,156 KB
testcase_09 AC 27 ms
24,156 KB
testcase_10 AC 59 ms
30,704 KB
testcase_11 AC 57 ms
30,600 KB
testcase_12 AC 179 ms
41,020 KB
testcase_13 AC 137 ms
37,732 KB
testcase_14 AC 175 ms
40,616 KB
testcase_15 AC 194 ms
41,932 KB
testcase_16 AC 78 ms
32,460 KB
testcase_17 AC 162 ms
40,032 KB
testcase_18 AC 36 ms
26,204 KB
testcase_19 AC 60 ms
30,772 KB
testcase_20 AC 163 ms
40,044 KB
testcase_21 AC 98 ms
34,652 KB
testcase_22 AC 219 ms
43,832 KB
testcase_23 AC 215 ms
43,844 KB
testcase_24 AC 92 ms
36,112 KB
testcase_25 AC 123 ms
40,312 KB
testcase_26 AC 65 ms
32,784 KB
testcase_27 AC 158 ms
46,576 KB
testcase_28 AC 30 ms
24,164 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 Program
    {
        public class Node
        {
            public int id;
            public List<Node> link = new List<Node>();

            public Node(int i)
            {
                id = i;
                link = new List<Node>();
            }
        }

        static void connect (Node a, Node b)
        {
            a.link.Add(b);
            b.link.Add(a);
            return;
        }
    	static void Main(string[] args)
    	{
            int n = int.Parse(Console.ReadLine());
            List<Node> nodes = new List<Node>();
            for (int i=0; i<n; i++) nodes.Add(new Node(i));
            for (int i=0; i<n-1; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                connect(nodes[int.Parse(s[0]) - 1], nodes[int.Parse(s[1]) - 1]);
            }
            int[] searchList = new int[n];
            for(int i=0; i<n; i++) searchList[i] = -1;
            List<int> queue = new List<int>();
            queue.Add(0);
            searchList[0] = 0;
            int lastId = 0;
            /*
            while(queue.Count > 0)
            {
                int id = queue[0];
                foreach(Node node in nodes[id].link)
                {
                    if (searchList[node.id] < 0){
                        searchList[node.id] = searchList[id] + 1;
                        queue.Add(node.id);
                    }
                }
                lastId = id;
                queue.Remove(id);
            }
            //Console.Error.WriteLine(lastId);
            int start = lastId;

            queue.Add(lastId);
            for(int i=0; i<n; i++) searchList[i] = -1;
            searchList[lastId] = 0;
            while(queue.Count > 0)
            {
                int id = queue[0];
                foreach(Node node in nodes[id].link)
                {
                    if (searchList[node.id] < 0){
                        searchList[node.id] = searchList[id] + 1;
                        queue.Add(node.id);
                    }
                }
                lastId = id;
                queue.Remove(id);
            }
            //Console.Error.WriteLine(start +  " " + lastId + " " + searchList[lastId]);
            Console.WriteLine(n - 1 - searchList[lastId]);
            */
            int ans = 0;
            foreach(Node node in nodes)
            {
                if (node.link.Count > 2) ans += node.link.Count - 2;
            }
            Console.WriteLine(ans);
            
        }
    }
    //mcs Main.cs
    //mono Main.exe
0