QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#582017 | #2517. Critical Structures | CSQ# | AC ✓ | 41ms | 19344kb | C++23 | 2.6kb | 2024-09-22 15:00:21 | 2024-09-22 15:00:24 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define all(x) begin(x),end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
int bridge = 0,cut = 0;
vi num, st;
vector<vector<pii>> ed;
int Time;
int dfs(int at, int par, vector<vector<int>> &f){
int me = num[at] = ++Time, e, y, top = me;
for (auto pa : ed[at]) if (pa.second != par){
tie(y, e) = pa;
if (num[y]){
top = min(top, num[y]);
if (num[y] < me)
st.push_back(e);
}
else {
int si = sz(st);
int up = dfs(y, e, f);
top = min(top, up);
if (up == me){
st.push_back(e);
f.push_back(vi(st.begin() + si, st.end()));
st.resize(si);
}
else if (up < me) st.push_back(e);
else { bridge++;}
}
}
return top;
}
int main()
{
int t;
cin>>t;
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
while(t--){
bridge = cut = Time = 0;
st.clear();
num.clear();
int n,m;
cin>>n>>m;
int eid = 0;
ed.resize(n);
for(int i=0;i<n;i++)ed[i].clear();
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
a--;
b--;
ed[a].push_back({b,eid});
ed[b].push_back({a,eid++});
}
vector<vector<int>>v;
num.assign(sz(ed),0);
for(int i=0;i<n;i++)if(!num[i])dfs(i,-1,v);
int mx = 1;
int id = 0;
vector<int>lab(m,-1);
for(auto x:v){
mx = max(mx,sz(x));
for(int y:x)lab[y] = id;
id++;
}
vector<int>seen(m,0);
for(int i=0;i<n;i++){
int cnt = 0;
for(pii x:ed[i]){
int c = lab[x.second];
if(c == -1)cnt++;
else{
if(!seen[c])cnt++;
seen[c] = 1;
}
}
for(pii x:ed[i]){
int c = lab[x.second];
if(c == -1)continue;
else seen[c] = 0;
}
if(cnt>1)cut++;
}
int comp = sz(v);
comp += bridge;
int g = gcd(comp,mx);
comp/=g;
mx/=g;
cout<<cut<<" "<<bridge<<" "<<comp<<" "<<mx<<'\n';
//cout<<"TES"<<'\n';
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3496kb
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: 3780kb
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: 41ms
memory: 19344kb
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