結果
| 問題 | No.8107 Listening |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-04-01 21:52:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 3,087 bytes |
| コンパイル時間 | 2,730 ms |
| コンパイル使用メモリ | 213,572 KB |
| 最終ジャッジ日時 | 2025-02-20 19:08:40 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 TLE * 11 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
struct GeneralMatching {
struct E {
int a, b;
};
const vector<vector<int>>& g;
int n, sz;
vector<int> p, t, mt;
vector<E> f;
int non(int v) { return t[v] != sz or p[v] == -1 ? v : (p[v] = non(p[v])); }
void R(int a, int b) {
int d = mt[a];
mt[a] = b;
if (d == -1 or mt[d] != a) return;
if (f[a].b == -1) {
mt[d] = f[a].a;
R(f[a].a, d);
} else {
R(f[a].a, f[a].b);
R(f[a].b, f[a].a);
}
}
bool arg(int rt) {
queue<int> q;
t[rt] = sz;
p[rt] = -1;
f[rt] = E{-1, -1};
q.push(rt);
while (!q.empty()) {
int a = q.front();
q.pop();
for (auto b : g[a]) {
if (b == rt) continue;
if (mt[b] == -1) {
mt[b] = a;
R(a, b);
return true;
}
if (t[b] == sz) {
int x = non(a), y = non(b);
if (x == y) continue;
int z = rt;
while (x != rt or y != rt) {
if (y != rt) swap(x, y);
if (f[x].a == a and f[x].b == b) {
z = x;
break;
}
f[x] = E{a, b};
x = non(f[mt[x]].a);
}
for (auto v : {non(a), non(b)}) {
while (v != z) {
t[v] = sz;
p[v] = z;
q.push(v);
v = non(f[mt[v]].a);
}
}
continue;
}
if (t[mt[b]] == sz) continue;
f[b] = E{-1, -1};
t[mt[b]] = sz;
p[mt[b]] = b;
f[mt[b]] = E{a, -1};
q.push(mt[b]);
}
}
return false;
}
GeneralMatching(const vector<vector<int>>& gg) : g(gg), n(g.size()), sz(0), p(n), t(n, -1), mt(n, -1), f(n) {
for (int i = 0; i < n; i++) {
if (mt[i] == -1) {
sz += arg(i);
}
}
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<vector<int>> G(N);
map<pair<int, int>, int> ID;
for(int i = 1; i <= M; i++) {
int u, v;
cin >> u >> v;
u--, v--;
G[u].emplace_back(v);
G[v].emplace_back(u);
ID[minmax(u, v)] = i;
}
GeneralMatching GM(G);
cout << GM.sz << '\n';
for (int i = 0; i < N; i++) {
if (i < GM.mt[i]) {
cout << ID[minmax(i, GM.mt[i])] << '\n';
// cout << i << ' ' << GM.mt[i] << '\n';
}
}
}
/*
https://judge.yosupo.jp/submission/116845
ここからパクりました。本当にごめんなさい...
*/