結果

問題 No.1254 補強への架け橋
ユーザー jupiro
提出日時 2020-10-14 22:30:40
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 2,395 bytes
コンパイル時間 1,594 ms
コンパイル使用メモリ 140,000 KB
最終ジャッジ日時 2025-01-15 07:20:28
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 123
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;
using ull = unsigned long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353;
constexpr int MAX = 1100000;

struct LowLink {
	int n, now_ord;
	vector<vector<int>> g;
	vector<int> ord, low;
	vector<bool> used;
	LowLink(int n) :n(n), now_ord(0), g(n), ord(n, -1), low(n), used(n) {}
	void add_edge(int from, int to) {
		g[from].emplace_back(to);
		g[to].emplace_back(from);
	}
	void dfs(int cur, int pre) {
		ord[cur] = low[cur] = now_ord++;
		for (auto nxt : g[cur]) {
			if (nxt == pre) continue;
			if (ord[nxt] == -1) {
				dfs(nxt, cur);
				chmin(low[cur], low[nxt]);
			}
			else {
				chmin(low[cur], ord[nxt]);
			}
		}
	}

	void build() {
		for (int i = 0; i < n; i++) if (ord[i] == -1) dfs(i, -1);
	}

	bool isbridge(int u, int v) {
		if (ord[u] == -1) build();
		if (ord[u] > ord[v]) swap(u, v);
		return ord[u] < low[v];
	}
};
int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n; cin >> n;
	LowLink lowlink(n);
	vector<tuple<int,int,int>> edge; edge.reserve(n);
	for (int i = 0; i < n; i++) {
		int u, v; cin >> u >> v;
		u--; v--;
		lowlink.add_edge(u, v);
		edge.emplace_back(u, v, i + 1);
	}
	lowlink.build();
	vector<int> res;
	for (auto& [u, v, id] : edge) {
		if (!lowlink.isbridge(u, v)) res.emplace_back(id);
	}
	cout << res.size() << "\n";
	for (int i = 0; i < res.size(); i++) cout << res[i] << " \n"[i + 1 == res.size()];
}
0