結果
| 問題 | No.1254 補強への架け橋 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2025-03-09 00:15:36 | 
| 言語 | C# (.NET 8.0.404) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 325 ms / 2,000 ms | 
| コード長 | 3,067 bytes | 
| コンパイル時間 | 8,337 ms | 
| コンパイル使用メモリ | 171,620 KB | 
| 実行使用メモリ | 248,728 KB | 
| 最終ジャッジ日時 | 2025-03-09 00:16:12 | 
| 合計ジャッジ時間 | 32,977 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 123 | 
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (112 ミリ秒)。 main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NMi => ReadLine().Split().Select(c => int.Parse(c) - 1).ToArray();
    static int[][] NMap(int n) => Enumerable.Repeat(0, n).Select(_ => NMi).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var n = NN;
        var map = NMap(n);
        var tree = new List<int>[n];
        for (var i = 0; i < n; ++i) tree[i] = new List<int>();
        for (var i = 0; i < n; ++i)
        {
            tree[map[i][0]].Add(map[i][1]);
            tree[map[i][1]].Add(map[i][0]);
        }
        var ntree = new Dictionary<int, int>[n];
        for (var i = 0; i < n; ++i) ntree[i] = new Dictionary<int, int>();
        for (var i = 0; i < n; ++i)
        {
            var f = Math.Min(map[i][0], map[i][1]);
            var t = Math.Max(map[i][0], map[i][1]);
            ntree[f].Add(t, i);
        }
        var isbridge = new bool[n];
        var ll = new LowLink(tree);
        foreach (var br in ll.bridge)
        {
            isbridge[ntree[br.f][br.t]] = true;
        }
        var ans = new List<int>();
        for (var i = 0; i < n; ++i) if (!isbridge[i]) ans.Add(i + 1);
        WriteLine(ans.Count);
        WriteLine(string.Join(" ", ans));
    }
    class LowLink
    {
        int v;
        int[] ord;
        int[] low;
        List<int>[] tree;
        /// <summary>関節点であればtrueとなる値のリスト</summary>
        public bool[] isArticulation;
        /// <summary>橋のリスト</summary>
        public List<(int f, int t)> bridge = new List<(int f, int t)>();
        public LowLink(List<int>[] _tree)
        {
            tree = _tree;
            v = _tree.Length;
            ord = Enumerable.Repeat(-1, v).ToArray();
            low = Enumerable.Repeat(-1, v).ToArray();
            isArticulation = new bool[v];
            for (var i = 0; i < v; ++i)
            {
                if (ord[i] == -1) DFS(i, -1, 0);
            }
        }
        int DFS(int cur, int prev, int c)
        {
            ord[cur] = c++;
            low[cur] = ord[cur];
            var childcnt = 0;
            foreach (var next in tree[cur])
            {
                if (ord[next] == -1)
                {
                    ++childcnt;
                    c = DFS(next, cur, c);
                    low[cur] = Math.Min(low[cur], low[next]);
                    if (prev != -1 && ord[cur] <= low[next]) isArticulation[cur] = true;
                    if (ord[cur] < low[next]) bridge.Add((Math.Min(cur, next), Math.Max(cur, next)));
                }
                else if (prev != next)
                {
                    low[cur] = Math.Min(low[cur], ord[next]);
                }
            }
            if (prev == -1 && childcnt > 1) isArticulation[cur] = true;
            return c;
        }
    }
}
            
            
            
        