QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#718488#2517. Critical Structuresyuto1115#AC ✓126ms46824kbC++201.7kb2024-11-06 20:39:222024-11-06 20:39:26

Judging History

你现在查看的是最新测评结果

  • [2024-11-06 20:39:26]
  • 评测
  • 测评结果:AC
  • 用时:126ms
  • 内存:46824kb
  • [2024-11-06 20:39:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define rep2(i,j,k) for(ll i = ll(j); i < ll(k); i++)
#define rep(i,k) rep2(i,0,k)
#define rrep2(i,j,k) for(ll i = ll(j)-1; i >= ll(k); i--)
#define rrep(i,k) rrep2(i,k,0)
#define all(a) a.begin(), a.end()
#define SZ(a) ll(a.size())
#define eb emplace_back
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;
const ll inf = LLONG_MAX/4;
bool chmin(auto& a, auto& b) {return a > b ? a = b, 1 : 0; }
bool chmax(auto& a, auto& b) {return a < b ? a = b, 1 : 0; }

void solve() {
	int n,m;
	cin >> n >> m;
	vvp G(n);
	rep(i, m) {
		int u, v;
		cin >> u >> v;
		--u, --v;
		G[u].eb(v, i);
		G[v].eb(u, i);
	}
	vl ls;
	vl cmp;
	int art = 0, brd = 0;
	int k = 0;
	vl ord(n, -1), low(n, -1);
	auto dfs = [&](auto &dfs, int u, int p) -> void {
		ord[u] = low[u] = k++;
		bool flag = false;
		int cnt = 0;
		for(auto [v,id] : G[u]) {
			if(ord[v] < 0) {
				ls.eb(id);
				++cnt;
				dfs(dfs, v, u);
				chmin(low[u], low[v]);
				if(low[v] > ord[u]) ++brd;
				if(low[v] >= ord[u]) {
					if(p >= 0) flag = true;
					set<ll> st;
					while(true) {
						assert(!ls.empty());
						int e = ls.back();
						st.insert(e);
						ls.pop_back();
						if(e == id) break;
					}
					cmp.eb(SZ(st));
				}
			} else if(v != p) {
				if(ord[v] < ord[u]) ls.eb(id);
				chmin(low[u], ord[v]);
			}
		}
		flag |= p < 0 and cnt > 1;
		if(flag) ++art;		
	};
	dfs(dfs, 0, -1);
	int p = SZ(cmp);
	int q = *max_element(all(cmp));
	int g = gcd(p, q);
	cout << art << ' ' << brd << ' ' << p/g << ' ' << q/g << '\n';
}
	

int main(){
	cin.tie(0)->sync_with_stdio(0);
	int t;
	cin >> t;
	rep(_, t) solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3824kb

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: 3532kb

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: 126ms
memory: 46824kb

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