72612024-01-05 16:21:58czitaElágazás nélküli úton levő települések (50 pont)csharpWrong answer 31/50119ms38812 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);
                    if (V[V[i][0]].Count > 1)
                    {
                        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
base31/50
1Accepted0/043ms24812 KiB
2Accepted0/0118ms36004 KiB
3Wrong answer0/243ms25848 KiB
4Accepted2/241ms25888 KiB
5Accepted2/239ms25992 KiB
6Wrong answer0/243ms26344 KiB
7Accepted2/245ms26328 KiB
8Accepted2/250ms28380 KiB
9Accepted2/254ms30232 KiB
10Accepted2/265ms32552 KiB
11Accepted2/282ms35572 KiB
12Accepted2/282ms36104 KiB
13Accepted3/346ms28600 KiB
14Wrong answer0/352ms30056 KiB
15Wrong answer0/354ms30632 KiB
16Wrong answer0/354ms31832 KiB
17Wrong answer0/376ms37192 KiB
18Wrong answer0/378ms37628 KiB
19Accepted3/383ms37972 KiB
20Accepted3/3118ms38532 KiB
21Accepted3/3118ms38812 KiB
22Accepted3/3119ms38532 KiB