using System; using System.Linq; using System.Collections.Generic; using System.Text; using System.Numerics; public class Solution { private IList[] graph; private bool[] visited; private int[] visitedTimes; private int[] lowVisitedTimes; private IList> criticalConnections; private int time; public IList> CriticalConnections(int n, IList> connections) { graph = new IList[n]; visited = new bool[n]; visitedTimes = new int[n]; lowVisitedTimes = new int[n]; criticalConnections = new List>(); time = 0; InitGraph(n, connections); DFS(0, -1); return criticalConnections; } private void DFS(int current, int parent) { visited[current] = true; visitedTimes[current] = lowVisitedTimes[current] = time++; foreach (var server in graph[current]) { if (server == parent) { continue; } if (!visited[server]) { DFS(server, current); if (visitedTimes[current] < lowVisitedTimes[server]) { criticalConnections.Add(new List(2) { current, server }); } else if (visitedTimes[current] > lowVisitedTimes[server]) { lowVisitedTimes[current] = lowVisitedTimes[server]; } } else { lowVisitedTimes[current] = Math.Min(lowVisitedTimes[current], visitedTimes[server]); } } } private void InitGraph(int n, IList> connections) { for (int i = 0; i < n; i++) { graph[i] = new List(); } foreach (var connection in connections) { var a = connection[0]; var b = connection[1]; graph[a].Add(b); graph[b].Add(a); } } } class MyClass { public static void Solve() { var N = int.Parse(Console.ReadLine()); var edges = new List>(); var dic = new Dictionary<(int, int), int>(); for (int i = 0; i < N; i++) { var data = Console.ReadLine().Split().Select(int.Parse).ToArray(); var A = data[0] - 1; var B = data[1] - 1; var edge = new List(); edge.Add(A); edge.Add(B); edges.Add(edge); dic.Add((A, B), i + 1); dic.Add((B, A), i + 1); } var sol = new Solution(); var pri = sol.CriticalConnections(N, edges); var ans = Enumerable.Range(1, N).ToHashSet(); foreach (var item in pri) { var A = item[0]; var B = item[1]; ans.Remove(dic[(A, B)]); } Console.WriteLine(ans.Count()); Console.WriteLine(string.Join(" ", ans)); } public static void Main() { var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } }