74652024-01-09 09:47:27CsongiElágazás nélküli úton levő települések (50 pont)csharpRuntime error 8/5064ms77388 KiB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace elagazas_nelkuli
{
    class Program
    {
        static int[] dfs(List<List<int>> csucslista, int v, int n, List<int> path = null, bool[] check = null, bool breakk = false)
        {
            if (path == null)
                path = new List<int>(n);
            if (check == null)
                check = new bool[n+1];
            path.Add(v);
            check[v] = true;
            foreach (int i in csucslista[v])
            {
                if (!check[i])
                {
                    if (csucslista[i].Count >= 3 && breakk == false)
                    {
                        breakk = true;
                        dfs(csucslista, i, n, path, check, breakk);
                        break;
                    }
                    else if (csucslista[i].Count < 3 && breakk == false)
                    {
                        dfs(csucslista, i, n, path, check, breakk);
                    }
                    /*else if (breakk)
                        break;*/
                }
                
            }
            return path.ToArray();
        }
        static void Main(string[] args)
        {
            int[] be = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = be[0];
            int m = be[1];
            List<List<int>> csucsok = new List<List<int>>(n+1);
            for (int i = 0; i <= n; i++)
            {
                csucsok.Add(new List<int>(n-1));
            }
            for (int i = 0; i < m; i++)
            {
                int[] bekeres = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                int a = bekeres[0];
                int b = bekeres[1];
                csucsok[a].Add(b);
                csucsok[b].Add(a);
            }
            List<int> zsakok = new List<int>(n);
            for (int i = 0; i < csucsok.Count; i++)
            {
                if (csucsok[i].Count == 1)
                    zsakok.Add(i);
            }
            List<int> dfss = new List<int>();
            for (int i = 0; i < zsakok.Count; i++)
            {
                int[] ki = dfs(csucsok, zsakok[i], n);
                foreach (int k in ki)
                    dfss.Add(k);
            }
            List<int> rendez = dfss.OrderBy(c => c).ToList();
            Console.WriteLine(rendez.Count-zsakok.Count);
            foreach (int i in rendez)
            {
                if (!zsakok.Contains(i))
                    Console.Write(i + " ");
            }
            if (rendez.Count - zsakok.Count == 0)
            {
                Console.WriteLine();
            }
            Console.ReadKey();
        }
    }
}
SubtaskSumTestVerdictTimeMemory
base8/50
1Accepted0/041ms22968 KiB
2Runtime error0/054ms77388 KiB
3Wrong answer0/239ms23560 KiB
4Wrong answer0/239ms23796 KiB
5Accepted2/235ms24264 KiB
6Wrong answer0/239ms24300 KiB
7Accepted2/239ms24732 KiB
8Accepted2/252ms43408 KiB
9Accepted2/264ms60268 KiB
10Runtime error0/254ms75508 KiB
11Runtime error0/254ms74984 KiB
12Runtime error0/250ms75028 KiB
13Wrong answer0/350ms44164 KiB
14Wrong answer0/361ms61568 KiB
15Runtime error0/359ms74604 KiB
16Runtime error0/352ms74632 KiB
17Runtime error0/352ms74624 KiB
18Runtime error0/352ms74160 KiB
19Runtime error0/352ms74236 KiB
20Runtime error0/352ms74148 KiB
21Runtime error0/352ms74100 KiB
22Runtime error0/352ms74240 KiB