74562024-01-09 09:43:43CsongiElágazás nélküli úton levő települések (50 pont)csharpWrong answer 23/50112ms43004 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>());
            }
            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
base23/50
1Accepted0/039ms22516 KiB
2Accepted0/0107ms33644 KiB
3Wrong answer0/239ms23228 KiB
4Wrong answer0/237ms23292 KiB
5Accepted2/235ms23712 KiB
6Wrong answer0/239ms24220 KiB
7Accepted2/239ms24360 KiB
8Accepted2/245ms26352 KiB
9Accepted2/252ms28508 KiB
10Accepted2/259ms30640 KiB
11Accepted2/275ms33240 KiB
12Accepted2/278ms34092 KiB
13Wrong answer0/345ms26736 KiB
14Wrong answer0/348ms28840 KiB
15Wrong answer0/354ms31180 KiB
16Wrong answer0/375ms35080 KiB
17Wrong answer0/374ms34884 KiB
18Wrong answer0/379ms43004 KiB
19Wrong answer0/386ms42568 KiB
20Accepted3/3109ms36736 KiB
21Accepted3/3112ms37056 KiB
22Accepted3/3108ms37480 KiB