結果

問題 No.1254 補強への架け橋
ユーザー packer_jppacker_jp
提出日時 2020-10-09 22:33:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 224 ms / 2,000 ms
コード長 4,429 bytes
コンパイル時間 2,527 ms
コンパイル使用メモリ 221,128 KB
実行使用メモリ 38,164 KB
最終ジャッジ日時 2023-09-27 18:27:25
合計ジャッジ時間 17,176 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 3 ms
4,380 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 3 ms
4,376 KB
testcase_49 AC 1 ms
4,376 KB
testcase_50 AC 3 ms
4,384 KB
testcase_51 AC 2 ms
4,376 KB
testcase_52 AC 3 ms
4,380 KB
testcase_53 AC 3 ms
4,380 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 2 ms
4,380 KB
testcase_56 AC 2 ms
4,380 KB
testcase_57 AC 2 ms
4,384 KB
testcase_58 AC 2 ms
4,376 KB
testcase_59 AC 2 ms
4,380 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 2 ms
4,380 KB
testcase_62 AC 1 ms
4,380 KB
testcase_63 AC 15 ms
5,664 KB
testcase_64 AC 5 ms
4,376 KB
testcase_65 AC 10 ms
4,772 KB
testcase_66 AC 8 ms
4,572 KB
testcase_67 AC 4 ms
4,380 KB
testcase_68 AC 9 ms
4,528 KB
testcase_69 AC 12 ms
4,908 KB
testcase_70 AC 5 ms
4,380 KB
testcase_71 AC 4 ms
4,376 KB
testcase_72 AC 12 ms
4,896 KB
testcase_73 AC 5 ms
4,380 KB
testcase_74 AC 11 ms
4,720 KB
testcase_75 AC 8 ms
4,568 KB
testcase_76 AC 3 ms
4,376 KB
testcase_77 AC 7 ms
4,744 KB
testcase_78 AC 14 ms
5,500 KB
testcase_79 AC 14 ms
5,348 KB
testcase_80 AC 13 ms
5,008 KB
testcase_81 AC 16 ms
5,456 KB
testcase_82 AC 13 ms
5,180 KB
testcase_83 AC 220 ms
25,980 KB
testcase_84 AC 214 ms
25,304 KB
testcase_85 AC 116 ms
17,420 KB
testcase_86 AC 183 ms
22,620 KB
testcase_87 AC 201 ms
24,356 KB
testcase_88 AC 23 ms
6,768 KB
testcase_89 AC 216 ms
25,712 KB
testcase_90 AC 129 ms
18,044 KB
testcase_91 AC 97 ms
15,168 KB
testcase_92 AC 43 ms
9,260 KB
testcase_93 AC 162 ms
21,808 KB
testcase_94 AC 147 ms
20,284 KB
testcase_95 AC 151 ms
19,920 KB
testcase_96 AC 213 ms
24,680 KB
testcase_97 AC 75 ms
13,244 KB
testcase_98 AC 214 ms
25,036 KB
testcase_99 AC 108 ms
16,332 KB
testcase_100 AC 224 ms
26,340 KB
testcase_101 AC 39 ms
8,764 KB
testcase_102 AC 19 ms
6,024 KB
testcase_103 AC 41 ms
9,212 KB
testcase_104 AC 61 ms
11,884 KB
testcase_105 AC 166 ms
21,736 KB
testcase_106 AC 79 ms
13,984 KB
testcase_107 AC 214 ms
25,672 KB
testcase_108 AC 214 ms
25,640 KB
testcase_109 AC 159 ms
21,940 KB
testcase_110 AC 140 ms
20,328 KB
testcase_111 AC 143 ms
21,148 KB
testcase_112 AC 55 ms
11,152 KB
testcase_113 AC 141 ms
19,036 KB
testcase_114 AC 79 ms
13,764 KB
testcase_115 AC 25 ms
6,780 KB
testcase_116 AC 96 ms
15,228 KB
testcase_117 AC 56 ms
11,468 KB
testcase_118 AC 199 ms
24,572 KB
testcase_119 AC 111 ms
16,340 KB
testcase_120 AC 188 ms
23,824 KB
testcase_121 AC 47 ms
10,048 KB
testcase_122 AC 91 ms
14,636 KB
testcase_123 AC 2 ms
4,376 KB
testcase_124 AC 211 ms
38,156 KB
testcase_125 AC 218 ms
38,164 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(a) (a).begin(), (a).end()
#define uniq(a) (a).erase(unique(all(a)), (a).end())
#define bit(n) (1LL << (n))
#define dump(a) cerr << #a " = " << (a) << endl
using vint = vector<int>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int sign(int a) { return (a > 0) - (a < 0); }
int cdiv(int a, int b) { return (a - 1 + b) / b; }
template<typename T> void fin(T a) {
    cout << a << endl;
    exit(0);
}
template<typename T> T sq(T a) { return a * a; }
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &a) {
    os << "(" << a.first << ", " << a.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &a) {
    os << "{";
    for (auto itr = a.begin(); itr != a.end(); itr++) {
        os << *itr << (next(itr) != a.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const deque<T> &a) {
    os << "{";
    for (auto itr = a.begin(); itr != a.end(); itr++) {
        os << *itr << (next(itr) != a.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const set<T> &a) {
    os << "{";
    for (auto itr = a.begin(); itr != a.end(); itr++) {
        os << *itr << (next(itr) != a.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &a) {
    os << "{";
    for (auto itr = a.begin(); itr != a.end(); itr++) {
        os << *itr << (next(itr) != a.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &a) {
    os << "{";
    for (auto itr = a.begin(); itr != a.end(); itr++) {
        os << *itr << (next(itr) != a.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

struct low_link {
    int n;
    std::vector<int> ord, low, articulations;
    std::vector<std::vector<int>> adj;
    std::vector<std::pair<int, int>> bridges;
    low_link(const std::vector<std::vector<int>> &adj) : n(adj.size()), adj(adj), ord(n), low(n) {
        std::vector<bool> visited(n);
        int k = 0;
        auto dfs = [&](auto &&self, int cur, int par) -> void {
            visited[cur] = true;
            ord[cur] = k++;
            low[cur] = ord[cur];
            int cnt = 0;
            bool is_articulation = false;
            for (int to : adj[cur]) {
                if (!visited[to]) {
                    cnt++;
                    self(self, to, cur);
                    low[cur] = std::min(low[cur], low[to]);
                    is_articulation |= ord[cur] <= low[to];
                    if (ord[cur] < low[to]) { bridges.emplace_back(std::minmax(cur, to)); }
                } else if (to != par) { low[cur] = std::min(low[cur], ord[to]); }
            }
            if (par == -1) { is_articulation = cnt >= 2; }
            if (is_articulation) { articulations.emplace_back(cur); }
        };
        dfs(dfs, 0, -1);
    }
};

signed main() {
    int N;
    cin >> N;
    vint a(N), b(N);
    vector<vint> adj(N);
    map<pint, int> idx;
    rep(i, N) {
        cin >> a[i] >> b[i], a[i]--, b[i]--;
        idx[minmax(a[i], b[i])] = i;
        adj[a[i]].emplace_back(b[i]);
        adj[b[i]].emplace_back(a[i]);
    }
    low_link ll(adj);
    cout << N - ll.bridges.size() << endl;
    vint ans(N, 1);
    for (pint p:ll.bridges) { ans[idx[p]] = 0; }
    rep(i, N) {
        if (ans[i]) { cout << i + 1 << " "; }
    }
    cout << endl;
}
0