72592024-01-05 16:18:16czitaElágazás nélküli úton levő települések (50 pont)csharpWrong answer 36/50120ms39760 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];
                    }
                    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/043ms24296 KiB
2Accepted0/0115ms36032 KiB
3Wrong answer0/241ms25376 KiB
4Accepted2/241ms25188 KiB
5Accepted2/239ms25604 KiB
6Accepted2/243ms26124 KiB
7Accepted2/243ms26244 KiB
8Accepted2/250ms28208 KiB
9Accepted2/257ms30228 KiB
10Accepted2/264ms32536 KiB
11Accepted2/283ms35700 KiB
12Accepted2/282ms36712 KiB
13Accepted3/348ms29000 KiB
14Wrong answer0/350ms30368 KiB
15Wrong answer0/354ms31136 KiB
16Wrong answer0/357ms31664 KiB
17Accepted3/375ms37608 KiB
18Wrong answer0/378ms37724 KiB
19Accepted3/386ms38576 KiB
20Accepted3/3115ms39168 KiB
21Accepted3/3120ms39220 KiB
22Accepted3/3116ms39760 KiB