結果

問題 No.1254 補強への架け橋
ユーザー packer_jppacker_jp
提出日時 2020-10-09 22:33:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 4,429 bytes
コンパイル時間 2,332 ms
コンパイル使用メモリ 222,892 KB
実行使用メモリ 38,528 KB
最終ジャッジ日時 2024-07-20 12:56:13
合計ジャッジ時間 14,273 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 2 ms
5,376 KB
testcase_49 AC 2 ms
5,376 KB
testcase_50 AC 3 ms
5,376 KB
testcase_51 AC 3 ms
5,376 KB
testcase_52 AC 2 ms
5,376 KB
testcase_53 AC 3 ms
5,376 KB
testcase_54 AC 3 ms
5,376 KB
testcase_55 AC 3 ms
5,376 KB
testcase_56 AC 2 ms
5,376 KB
testcase_57 AC 2 ms
5,376 KB
testcase_58 AC 2 ms
5,376 KB
testcase_59 AC 2 ms
5,376 KB
testcase_60 AC 2 ms
5,376 KB
testcase_61 AC 2 ms
5,376 KB
testcase_62 AC 2 ms
5,376 KB
testcase_63 AC 14 ms
5,760 KB
testcase_64 AC 4 ms
5,376 KB
testcase_65 AC 10 ms
5,376 KB
testcase_66 AC 8 ms
5,376 KB
testcase_67 AC 4 ms
5,376 KB
testcase_68 AC 9 ms
5,376 KB
testcase_69 AC 10 ms
5,376 KB
testcase_70 AC 6 ms
5,376 KB
testcase_71 AC 5 ms
5,376 KB
testcase_72 AC 11 ms
5,376 KB
testcase_73 AC 5 ms
5,376 KB
testcase_74 AC 10 ms
5,376 KB
testcase_75 AC 8 ms
5,376 KB
testcase_76 AC 3 ms
5,376 KB
testcase_77 AC 7 ms
5,376 KB
testcase_78 AC 13 ms
5,504 KB
testcase_79 AC 14 ms
5,504 KB
testcase_80 AC 11 ms
5,376 KB
testcase_81 AC 16 ms
5,632 KB
testcase_82 AC 13 ms
5,504 KB
testcase_83 AC 162 ms
26,368 KB
testcase_84 AC 155 ms
25,536 KB
testcase_85 AC 90 ms
17,208 KB
testcase_86 AC 152 ms
22,616 KB
testcase_87 AC 146 ms
24,520 KB
testcase_88 AC 20 ms
6,784 KB
testcase_89 AC 158 ms
25,948 KB
testcase_90 AC 94 ms
17,976 KB
testcase_91 AC 71 ms
15,100 KB
testcase_92 AC 38 ms
9,404 KB
testcase_93 AC 119 ms
21,984 KB
testcase_94 AC 112 ms
20,508 KB
testcase_95 AC 115 ms
20,208 KB
testcase_96 AC 176 ms
24,840 KB
testcase_97 AC 69 ms
13,208 KB
testcase_98 AC 197 ms
25,284 KB
testcase_99 AC 102 ms
16,596 KB
testcase_100 AC 187 ms
26,356 KB
testcase_101 AC 34 ms
8,780 KB
testcase_102 AC 18 ms
6,272 KB
testcase_103 AC 37 ms
9,344 KB
testcase_104 AC 54 ms
11,956 KB
testcase_105 AC 139 ms
22,004 KB
testcase_106 AC 72 ms
14,288 KB
testcase_107 AC 174 ms
25,964 KB
testcase_108 AC 165 ms
25,660 KB
testcase_109 AC 128 ms
21,928 KB
testcase_110 AC 113 ms
20,336 KB
testcase_111 AC 127 ms
21,328 KB
testcase_112 AC 49 ms
11,116 KB
testcase_113 AC 111 ms
19,040 KB
testcase_114 AC 67 ms
13,860 KB
testcase_115 AC 23 ms
7,040 KB
testcase_116 AC 79 ms
15,404 KB
testcase_117 AC 50 ms
11,664 KB
testcase_118 AC 174 ms
24,828 KB
testcase_119 AC 91 ms
16,424 KB
testcase_120 AC 165 ms
24,228 KB
testcase_121 AC 41 ms
10,136 KB
testcase_122 AC 74 ms
15,072 KB
testcase_123 AC 2 ms
5,376 KB
testcase_124 AC 171 ms
38,528 KB
testcase_125 AC 175 ms
38,400 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