QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#707334 | #2517. Critical Structures | becaido | AC ✓ | 29ms | 11664kb | C++20 | 3.6kb | 2024-11-03 15:33:03 | 2024-11-03 15:33:05 |
Judging History
answer
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#ifdef WAIMAI
#define debug(HEHE...) cout<<"["<<#HEHE<<"] : ",dout(HEHE)
void dout(){cout<<'\n';}
template<typename T,typename...U>
void dout(T t,U...u){cout<<t<<(sizeof...(u)?", ":""),dout(u...);}
#else
#define debug(...) 7122
#endif
#define int long long
#define ll long long
#define Waimai ios::sync_with_stdio(false),cin.tie(0)
#define FOR(x,a,b) for(int x=a,I=b;x<=I;x++)
#define pb emplace_back
#define F first
#define S second
const int SIZE = 1005;
int n, m;
vector<int> adj[SIZE];
struct BCC_BRIDGE {
int dfcnt, bccnt;
int dfn[SIZE], low[SIZE], bcc[SIZE];
vector<int> st;
void init() {
dfcnt = bccnt = 0;
st.clear();
FOR (i, 1, n) dfn[i] = low[i] = bcc[i] = 0;
}
void tarjan (int pos, int fa) {
dfn[pos] = low[pos] = ++dfcnt;
st.pb (pos);
for (int np : adj[pos]) if (np != fa) {
if (!dfn[np]) {
tarjan (np, pos);
low[pos] = min (low[pos], low[np]);
if (dfn[pos] < low[np]) {
bccnt++;
while (1) {
int x = st.back();
bcc[x] = bccnt;
st.pop_back();
if (x == np) break;
}
}
} else {
low[pos] = min (low[pos], dfn[np]);
}
}
if (pos == fa) {
bccnt++;
while (st.size()) {
int x = st.back();
bcc[x] = bccnt;
st.pop_back();
}
}
}
} bcc_b;
struct BCC_POINT {
int dfcnt, bccnt;
int dfn[SIZE], low[SIZE];
vector<int> st, bcc[SIZE];
void init() {
dfcnt = bccnt = 0;
st.clear();
FOR (i, 1, n) dfn[i] = low[i] = 0, bcc[i].clear();
}
void tarjan (int pos, int fa) {
dfn[pos] = low[pos] = ++dfcnt;
st.pb (pos);
for (int np : adj[pos]) if (np != fa) {
if (!dfn[np]) {
tarjan (np, pos);
low[pos] = min (low[pos], low[np]);
if (dfn[pos] <= low[np]) {
bccnt++;
while (1) {
int x = st.back();
bcc[x].pb (bccnt);
st.pop_back();
if (x == np) break;
}
bcc[pos].pb (bccnt);
}
} else {
low[pos] = min (low[pos], dfn[np]);
}
}
}
} bcc_p;
void solve() {
cin >> n >> m;
bcc_b.init();
bcc_p.init();
FOR (i, 1, n) adj[i].clear();
while (m--) {
int a, b;
cin >> a >> b;
adj[a].pb (b);
adj[b].pb (a);
}
bcc_b.tarjan (1, 1);
bcc_p.tarjan (1, 1);
int cnt = 0;
FOR (i, 1, n) cnt += bcc_p.bcc[i].size() > 1;
cout << cnt << ' ' << bcc_b.bccnt - 1 << ' ';
int x, y = bcc_b.bccnt > 1;
int sum[bcc_b.bccnt + 1] = {};
x = bcc_b.bccnt - 1;
FOR (i, 1, n) sum[bcc_b.bcc[i]]++;
FOR (i, 1, bcc_b.bccnt) x += sum[i] >= 2;
memset (sum, 0, sizeof (sum));
FOR (i, 1, n) for (int j : adj[i]) sum[bcc_b.bcc[i]] += bcc_b.bcc[i] == bcc_b.bcc[j];
y = max (y, *max_element (sum + 1, sum + bcc_b.bccnt + 1) / 2);
int g = __gcd (x, y);
cout << x / g << ' ' << y / g << '\n';
}
int32_t main() {
Waimai;
int tt;
cin >> tt;
while (tt--) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3760kb
input:
1 6 6 1 2 2 3 3 4 4 5 5 6 6 1
output:
0 0 1 6
result:
ok single line: '0 0 1 6'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
1 6 7 1 2 2 3 3 1 4 5 5 6 6 4 1 4
output:
2 1 1 1
result:
ok single line: '2 1 1 1'
Test #3:
score: 0
Accepted
time: 29ms
memory: 11664kb
input:
10 6 6 1 2 2 3 3 4 4 5 5 6 6 1 5 4 1 2 2 3 3 4 4 5 5 7 1 2 1 3 3 4 4 5 5 3 1 4 1 5 13 16 1 2 1 6 1 3 1 7 3 7 4 6 4 5 5 6 5 7 7 8 8 9 7 10 10 11 12 13 10 12 10 13 10 11 1 2 2 3 2 4 3 5 4 5 4 6 6 7 7 8 6 8 8 9 8 10 3 3 1 2 2 3 3 1 44 66 1 5 1 12 1 33 2 27 2 31 2 32 2 35 2 37 2 40 3 6 3 30 3 44 4 20 4 ...
output:
0 0 1 6 3 4 4 1 1 1 1 3 4 5 7 8 4 4 3 2 0 0 1 3 8 9 10 57 0 0 1 499500 2 2 3 1777 108 112 113 1531
result:
ok 10 lines