結果

問題 No.1254 補強への架け橋
ユーザー chocopuuchocopuu
提出日時 2020-10-09 22:44:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 3,258 bytes
コンパイル時間 2,354 ms
コンパイル使用メモリ 224,612 KB
実行使用メモリ 32,148 KB
最終ジャッジ日時 2023-09-27 18:40:45
合計ジャッジ時間 13,372 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 1 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,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,376 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,376 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 2 ms
4,380 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 2 ms
4,376 KB
testcase_56 AC 1 ms
4,376 KB
testcase_57 AC 2 ms
4,376 KB
testcase_58 AC 2 ms
4,376 KB
testcase_59 AC 2 ms
4,380 KB
testcase_60 AC 2 ms
4,380 KB
testcase_61 AC 3 ms
4,376 KB
testcase_62 AC 1 ms
4,376 KB
testcase_63 AC 11 ms
4,660 KB
testcase_64 AC 4 ms
4,376 KB
testcase_65 AC 8 ms
4,376 KB
testcase_66 AC 7 ms
4,376 KB
testcase_67 AC 3 ms
4,380 KB
testcase_68 AC 7 ms
4,376 KB
testcase_69 AC 9 ms
4,384 KB
testcase_70 AC 6 ms
4,380 KB
testcase_71 AC 3 ms
4,380 KB
testcase_72 AC 9 ms
4,584 KB
testcase_73 AC 4 ms
4,376 KB
testcase_74 AC 8 ms
4,380 KB
testcase_75 AC 7 ms
4,376 KB
testcase_76 AC 2 ms
4,376 KB
testcase_77 AC 6 ms
4,376 KB
testcase_78 AC 10 ms
4,516 KB
testcase_79 AC 11 ms
4,640 KB
testcase_80 AC 10 ms
4,380 KB
testcase_81 AC 10 ms
4,548 KB
testcase_82 AC 10 ms
4,680 KB
testcase_83 AC 129 ms
19,300 KB
testcase_84 AC 133 ms
18,888 KB
testcase_85 AC 70 ms
13,076 KB
testcase_86 AC 105 ms
16,772 KB
testcase_87 AC 130 ms
18,216 KB
testcase_88 AC 16 ms
5,776 KB
testcase_89 AC 118 ms
19,220 KB
testcase_90 AC 75 ms
13,928 KB
testcase_91 AC 57 ms
11,644 KB
testcase_92 AC 31 ms
7,440 KB
testcase_93 AC 100 ms
16,232 KB
testcase_94 AC 91 ms
14,936 KB
testcase_95 AC 90 ms
15,040 KB
testcase_96 AC 117 ms
18,480 KB
testcase_97 AC 48 ms
10,076 KB
testcase_98 AC 119 ms
18,780 KB
testcase_99 AC 71 ms
12,488 KB
testcase_100 AC 125 ms
19,868 KB
testcase_101 AC 27 ms
6,860 KB
testcase_102 AC 13 ms
5,432 KB
testcase_103 AC 29 ms
7,408 KB
testcase_104 AC 42 ms
9,076 KB
testcase_105 AC 96 ms
16,052 KB
testcase_106 AC 54 ms
10,920 KB
testcase_107 AC 124 ms
19,288 KB
testcase_108 AC 128 ms
19,300 KB
testcase_109 AC 96 ms
16,000 KB
testcase_110 AC 89 ms
14,744 KB
testcase_111 AC 94 ms
15,532 KB
testcase_112 AC 39 ms
8,600 KB
testcase_113 AC 80 ms
14,364 KB
testcase_114 AC 53 ms
10,628 KB
testcase_115 AC 17 ms
5,848 KB
testcase_116 AC 63 ms
11,592 KB
testcase_117 AC 40 ms
8,820 KB
testcase_118 AC 116 ms
18,360 KB
testcase_119 AC 68 ms
12,456 KB
testcase_120 AC 116 ms
17,872 KB
testcase_121 AC 33 ms
8,084 KB
testcase_122 AC 57 ms
11,744 KB
testcase_123 AC 1 ms
4,376 KB
testcase_124 AC 136 ms
32,104 KB
testcase_125 AC 133 ms
32,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
//#include "atcoder/all"
//using namespace atcoder;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

struct Edge {
    int to;
};
using Graph = vector<vector<Edge>>;
using P = pair<long, long>;
/* Lowlink: グラフの関節点・橋を列挙する構造体
    作成: O(E+V)
    関節点の集合: vector<int> aps
    橋の集合: vector<P> bridges
*/
struct LowLink {
    const Graph &G;
    vector<int> used, ord, low;
    vector<int> aps;  // articulation points
    vector<P> bridges;
    LowLink(const Graph &G_) : G(G_) {
        used.assign(G.size(), 0);
        ord.assign(G.size(), 0);
        low.assign(G.size(), 0);
        int k = 0;
        for (int i = 0; i < (int)G.size(); i++) {
            if (!used[i]) k = dfs(i, k, -1);
        }
        sort(aps.begin(), aps.end()); // 必要ならソートする
        sort(bridges.begin(), bridges.end()); // 必要ならソートする
    }
    int dfs(int id, int k, int par) { // id:探索中の頂点, k:dfsで何番目に探索するか, par:idの親
        used[id] = true;
        ord[id] = k++;
        low[id] = ord[id];
        bool is_aps = false;
        int count = 0; // 子の数
        for (auto &e : G[id]) {
            if (!used[e.to]) {
                count++;
                k = dfs(e.to, k, id);
                low[id] = min(low[id], low[e.to]);
                if (par != -1 && ord[id] <= low[e.to]) is_aps = true; 
                if (ord[id] < low[e.to]) bridges.emplace_back(min(id, e.to), max(id, e.to)); // 条件を満たすので橋  
            } else if (e.to != par) { // eが後退辺の時
                low[id] = min(low[id], ord[e.to]);
            }
        }
        if (par == -1 && count >= 2) is_aps = true; 
        if (is_aps) aps.push_back(id);
        return k;
    }
};

signed main(){
	int N;
	cin >> N;
	Graph g(N);
	vector<int>a(N), b(N);
	REP(i, N) {
		cin >> a[i] >> b[i];
		--a[i]; --b[i];
		Edge A, B;
		A.to = a[i];
		B.to = b[i];
		g[a[i]].emplace_back(B);
		g[b[i]].emplace_back(A);
	}
	auto ll = LowLink(g);
	vector<int>ans;
	REP(i, N) {
		if(ll.ord[b[i]] < ll.low[a[i]]) ans.emplace_back(i);
		if(ll.ord[a[i]] < ll.low[b[i]]) ans.emplace_back(i);
	}
	sort(ans.begin(), ans.end());
	ans.erase(unique(ans.begin(), ans.end()), ans.end());
	//out(ans.size());
	set<int>st;
	REP(i, N) st.insert(i);
	REP(i, ans.size()) st.erase(ans[i]);
	ans.clear();
	for(auto e: st) ans.emplace_back(e + 1);
	out(ans.size());
	REP(i,ans.size())cout << ans[i] << " \n"[i+1 == ans.size()];
}
0