74682024-01-09 09:49:24CsongiElágazás nélküli úton levő települések (50 pont)csharpRuntime error 8/5068ms77772 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>();
            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>();
            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/041ms22512 KiB
2Runtime error0/054ms77772 KiB
3Wrong answer0/239ms22908 KiB
4Wrong answer0/239ms23380 KiB
5Accepted2/235ms23732 KiB
6Wrong answer0/239ms24348 KiB
7Accepted2/239ms24492 KiB
8Accepted2/252ms42440 KiB
9Accepted2/268ms59204 KiB
10Runtime error0/261ms75624 KiB
11Runtime error0/261ms75500 KiB
12Runtime error0/261ms75364 KiB
13Wrong answer0/350ms43840 KiB
14Wrong answer0/359ms60308 KiB
15Runtime error0/359ms74768 KiB
16Runtime error0/359ms74696 KiB
17Runtime error0/359ms74672 KiB
18Runtime error0/359ms74316 KiB
19Runtime error0/354ms74312 KiB
20Runtime error0/359ms73980 KiB
21Runtime error0/357ms74024 KiB
22Runtime error0/354ms73788 KiB