72632024-01-05 16:28:26czitaElágazás nélküli úton levő települések (50 pont)csharpWrong answer 36/50118ms38468 KiB
using System;
using System.Collections.Generic;
using System.Linq;


namespace lenelktel
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] st = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int N = st[0];
            int M = st[1];
            List<List<int>> V = new List<List<int>>();
            for (int i = 0; i < N + 1; i++)
            {
                V.Add(new List<int>());
            }
            for (int i = 0; i < M; i++)
            {
                st = Console.ReadLine().Split().Select(int.Parse).ToArray();
                V[st[0]].Add(st[1]);
                V[st[1]].Add(st[0]);
            }
            HashSet<int> zsakfalu = new HashSet<int>();
            List<int> jotel = new List<int>();
            HashSet<int> megold = new HashSet<int>();
            bool[] volt = new bool[N + 1];
            for (int i = 0; i < V.Count; i++)
            {
                if (V[i].Count == 1)
                {
                    zsakfalu.Add(i);

                    jotel.Add(V[i][0]);
                    megold.Add(V[i][0]);

                }
            }
            foreach (var item in jotel)
            {
                int tel = item, kovtel;
                while (V[tel].Count == 2 && !volt[tel])
                {
                    kovtel = V[tel][0];
                    if (zsakfalu.Contains(V[tel][0]))
                    {
                        kovtel = V[tel][1];
                    }
                    if (V[kovtel].Count > 1)
                    {
                        megold.Add(kovtel);
                    }

                    volt[tel] = true;
                    tel = kovtel;
                }
            }
            Console.WriteLine(megold.Count);
            Console.WriteLine(string.Join(" ", new SortedSet<int>(megold)));
            Console.ReadKey();
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base36/50
1Accepted0/043ms24512 KiB
2Accepted0/0118ms35788 KiB
3Wrong answer0/241ms25608 KiB
4Accepted2/241ms25792 KiB
5Accepted2/239ms25508 KiB
6Accepted2/243ms25956 KiB
7Accepted2/243ms26328 KiB
8Accepted2/248ms28156 KiB
9Accepted2/256ms29820 KiB
10Accepted2/261ms32128 KiB
11Accepted2/276ms35100 KiB
12Accepted2/279ms35968 KiB
13Accepted3/346ms27988 KiB
14Wrong answer0/350ms29344 KiB
15Wrong answer0/352ms30472 KiB
16Wrong answer0/356ms31040 KiB
17Accepted3/375ms36900 KiB
18Wrong answer0/378ms37124 KiB
19Accepted3/387ms37512 KiB
20Accepted3/3115ms38316 KiB
21Accepted3/3115ms38296 KiB
22Accepted3/3115ms38468 KiB