47642023-03-31 11:28:20TortelliniJrParti (75 pont)csharpWrong answer 3/75111ms44616 KiB
using System;
using System.Collections.Generic;
using System.Linq;

class MainClass
{
    static int n, ksz;
    static List<int>[] g;
    static List<int>[] g2;
    static bool[] volt;
    static bool[] volt2;
    static List<int> top;
    static int[] scc;

    static void dfs(int x)
    {
        if (volt[x]) return;
        volt[x] = true;
        foreach (int i in g[x]) dfs(i);
        top.Add(x);
    }

    static void dfs2(int y)
    {
        if (volt2[y]) return;
        volt2[y] = true;
        foreach (int i in g2[y]) dfs2(i);
        scc[y] = ksz;
    }

    public static void Main(string[] args)
    {
        n = int.Parse(Console.ReadLine());
        g = new List<int>[n + 1];
        g2 = new List<int>[n + 1];
        for (int i = 1; i <= n; ++i)
        {
            g[i] = new List<int>();
            g2[i] = new List<int>();
        }
        volt = new bool[n + 1];
        volt2 = new bool[n + 1];
        top = new List<int>();
        scc = new int[n + 1];
        for (int i = 1; i <= n; ++i)
        {
            string[] input = Console.ReadLine().Split();
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            g[i].Add(a);
            g[i].Add(b);
            g2[a].Add(i);
            g2[b].Add(i);
        }
        for (int i = 1; i <= n; ++i) dfs(i);
        top.Reverse();
        foreach (int cs in top)
        {
            if (!volt2[cs])
            {
                ++ksz;
                dfs2(cs);
            }
        }
        bool[] joscc = new bool[ksz + 1];
        for (int i = 1; i <= n; ++i)
        {
            int db = 0;
            foreach (int j in g2[i])
            {
                if (scc[j] == scc[i])
                {
                    ++db;
                }
            }
            if (db != 2)
            {
                joscc[scc[i]] = false;
            }
        }
        int[] cnt = new int[ksz + 1];
        for (int i = 1; i <= n; ++i)
        {
            ++cnt[scc[i]];
        }
        int maxscc = 0, maxcnt = 0;
        for (int i = 1; i <= ksz; ++i)
        {
            if ((maxscc == 0 || maxcnt < cnt[i]) && joscc[i])
            {
                maxscc = i;
                maxcnt = cnt[i];
            }
        }
        Console.WriteLine(maxcnt);
        for (int i = 1; i <= n; ++i)
        {
            if (scc[i] == maxscc)
            {
                Console.Write(i + " ");
            }
        }
        Console.WriteLine();
    }
}
SubtaskSumTestVerdictTimeMemory
base3/75
1Wrong answer0/032ms20204 KiB
2Runtime error0/0111ms44616 KiB
3Wrong answer0/329ms20952 KiB
4Wrong answer0/330ms21724 KiB
5Accepted3/330ms21748 KiB
6Wrong answer0/330ms22724 KiB
7Wrong answer0/330ms22784 KiB
8Wrong answer0/432ms23332 KiB
9Wrong answer0/432ms24068 KiB
10Wrong answer0/435ms24952 KiB
11Wrong answer0/432ms24992 KiB
12Wrong answer0/435ms26040 KiB
13Wrong answer0/437ms27252 KiB
14Wrong answer0/439ms28612 KiB
15Runtime error0/441ms41476 KiB
16Runtime error0/439ms41424 KiB
17Runtime error0/439ms41288 KiB
18Runtime error0/439ms41248 KiB
19Runtime error0/439ms41156 KiB
20Runtime error0/439ms41220 KiB
21Runtime error0/439ms40724 KiB
22Wrong answer0/430ms24788 KiB