QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#581653 | #2517. Critical Structures | CSQ# | WA | 35ms | 21284kb | C++23 | 2.2kb | 2024-09-22 13:46:20 | 2024-09-22 13:46:21 |
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;
int cnt = 0;
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){
//cout<<at<<" "<<y<<'\n';
cnt++;
if(par != -1)cut++;
else if(cnt>1)cut++;
}
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();
vector<array<int,2>>ee;
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
a--;
b--;
ee.push_back({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<sz(ed);i++)if(!num[i])dfs(i,-1,v);
vector<int>seen(n,0);
int mx = 0;
for(auto x:v){
mx = max(mx,sz(x));
}
int comp = sz(v);
comp += bridge;
int g = gcd(comp,mx);
comp/=g;
mx/=g;
cout<<cut<<" "<<bridge<<" "<<comp<<" "<<mx<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
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: 3792kb
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: -100
Wrong Answer
time: 35ms
memory: 21284kb
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 1 0 1 1 1 3 6 5 7 8 5 4 3 2 0 0 1 3 9 9 10 57 0 0 1 499500 2 2 3 1777 112 112 113 1531
result:
wrong answer 2nd lines differ - expected: '3 4 4 1', found: '3 4 1 0'