結果
| 問題 |
No.1254 補強への架け橋
|
| コンテスト | |
| ユーザー |
🍮かんプリン
|
| 提出日時 | 2020-10-10 01:45:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 273 ms / 2,000 ms |
| コード長 | 2,017 bytes |
| コンパイル時間 | 1,942 ms |
| コンパイル使用メモリ | 186,452 KB |
| 実行使用メモリ | 27,904 KB |
| 最終ジャッジ日時 | 2024-07-20 15:23:22 |
| 合計ジャッジ時間 | 16,046 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 123 |
ソースコード
/**
* @FileName a.cpp
* @Author kanpurin
* @Created 2020.10.10 01:45:40
**/
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
struct LowLink {
private:
vector< vector< int > > G;
int V;
vector< int > used, ord, low;
int dfs(int idx, int k, int par) {
used[idx] = true;
ord[idx] = k++;
low[idx] = ord[idx];
bool is_articulation = false;
int cnt = 0;
for (auto &to : G[idx]) {
if (!used[to]) {
++cnt;
k = dfs(to, k, idx);
low[idx] = min(low[idx], low[to]);
is_articulation |= ~par && low[to] >= ord[idx];
if (ord[idx] < low[to]) bridge.push_back(minmax(idx, (int)to));
}
else if (to != par) {
low[idx] = min(low[idx], ord[to]);
}
}
is_articulation |= par == -1 && cnt > 1;
if (is_articulation) articulation.push_back(idx);
return k;
}
public:
vector< int > articulation;
vector< pair< int, int > > bridge;
LowLink(int V) : V(V) {
G.resize(V);
}
void add_edge(int v, int u) {
G[v].push_back(u);
G[u].push_back(v);
}
void build() {
used.assign(V, 0);
ord.assign(V, 0);
low.assign(V, 0);
int k = 0;
for (int i = 0; i < V; i++) {
if (!used[i]) k = dfs(i, k, -1);
}
}
};
int main() {
int n;cin >> n;
LowLink g(n);
vector<pair<int,int>> edge(n);
map<pair<int,int>,int> mp;
for (int i = 0; i < n; i++) {
int a,b;cin >> a >> b;
a--;b--;
edge[i] = {a,b};
mp[{a,b}] = i+1;
g.add_edge(a,b);
}
g.build();
cout << n - g.bridge.size() << endl;
for (auto p : g.bridge) {
mp[p] = -1;
mp[{p.second,p.first}] = -1;
}
for (int i = 0; i < n; i++) {
if (mp[edge[i]] != -1) cout << i+1 << " ";
}
cout << endl;
return 0;
}
🍮かんプリン