結果
| 問題 |
No.1254 補強への架け橋
|
| コンテスト | |
| ユーザー |
emthrm
|
| 提出日時 | 2020-10-09 22:15:37 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 263 ms / 2,000 ms |
| コード長 | 3,402 bytes |
| コンパイル時間 | 2,317 ms |
| コンパイル使用メモリ | 216,524 KB |
| 最終ジャッジ日時 | 2025-01-15 04:55:08 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 123 |
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
IOSetup() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
}
} iosetup;
template <typename CostType>
struct Edge {
int src, dst; CostType cost;
Edge(int src, int dst, CostType cost = 0) : src(src), dst(dst), cost(cost) {}
inline bool operator<(const Edge &x) const {
return cost != x.cost ? cost < x.cost : dst != x.dst ? dst < x.dst : src < x.src;
}
inline bool operator<=(const Edge &x) const { return !(x < *this); }
inline bool operator>(const Edge &x) const { return x < *this; }
inline bool operator>=(const Edge &x) const { return !(*this < x); }
};
template <typename CostType>
struct Lowlink {
using E = Edge<CostType>;
std::vector<std::vector<E>> graph;
std::vector<int> ap;
std::vector<E> bridge;
Lowlink(const std::vector<std::vector<E>> &graph) : graph(graph) {
int n = graph.size();
order.assign(n, -1);
lowlink.resize(n);
int tm = 0;
for (int i = 0; i < n; ++i) {
if (order[i] == -1) dfs(-1, i, tm);
}
// std::sort(ap.begin(), ap.end());
// std::sort(bridge.begin(), bridge.end(), [](const E &a, const E &b) -> bool {
// return a.src != b.src ? a.src < b.src : a.dst != b.dst ? a.dst < b.dst : a.cost < b.cost;
// });
}
std::vector<int> order, lowlink;
private:
void dfs(int par, int ver, int &tm) {
order[ver] = lowlink[ver] = tm++;
int cnt = 0;
bool is_ap = false;
for (const E &e : graph[ver]) {
if (order[e.dst] == -1) {
++cnt;
dfs(ver, e.dst, tm);
if (lowlink[e.dst] < lowlink[ver]) lowlink[ver] = lowlink[e.dst];
if (order[ver] <= lowlink[e.dst]) {
is_ap = true;
if (order[ver] < lowlink[e.dst]) bridge.emplace_back(std::min(ver, e.dst), std::max(ver, e.dst), e.cost);
}
} else if (e.dst != par) {
if (order[e.dst] < lowlink[ver]) lowlink[ver] = order[e.dst];
}
}
if (par == -1) {
if (cnt >= 2) ap.emplace_back(ver);
} else {
if (is_ap) ap.emplace_back(ver);
}
}
};
int main() {
int n; cin >> n;
vector<vector<Edge<bool>>> graph(n);
map<pair<int, int>, int> mp;
REP(i, n) {
int a, b; cin >> a >> b; --a; --b;
if (a > b) swap(a, b);
mp[{a, b}] = i;
graph[a].emplace_back(a, b);
graph[b].emplace_back(b, a);
}
set<int> st;
REP(i, n) st.emplace(i);
for (auto &e : Lowlink(graph).bridge) {
int p = e.src, q = e.dst;
if (p > q) swap(p, q);
st.erase(mp[{p, q}]);
}
vector<int> ans(st.begin(), st.end());
int k = ans.size();
cout << k << '\n';
REP(i, k) cout << ans[i] + 1 << " \n"[i + 1 == k];
return 0;
}
emthrm