QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#762132#2517. Critical StructuresSanguineChameleon#AC ✓35ms30040kbC++202.8kb2024-11-19 13:52:172024-11-19 13:52:19

Judging History

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

  • [2024-11-19 13:52:19]
  • 评测
  • 测评结果:AC
  • 用时:35ms
  • 内存:30040kb
  • [2024-11-19 13:52:17]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
#define mp make_pair
#define eb emplace_back
#define pb push_back
typedef pair<int,int> pii;

const int mxn = 1005;
const int mxm = 1000005;

vector<pii> adjl[mxn];

int cols[mxm],nex_col;
int cnt[mxm], max_cnt;

int dep[mxn];
int be[mxn];//among all the descendants and ourselves, what's the shallowest back edge
int art_pts,bridges;
void dfs(int nd, int p=-1){
    be[nd]=dep[nd];
    int conns=dep[nd];
    int children_cnt=0;
    int maxi=0;
    for(pii nex:adjl[nd]){
        int x=nex.f;//the node
        // int id = nex.s;//edge id
        if(x==p)continue;
        if(dep[x]!=-1){
            //back edge
            conns=min(conns, dep[x]);
            continue;
        }
        dep[x]=dep[nd]+1;
        dfs(x,nd);
        children_cnt++;

        be[nd] = min(be[nd], be[x]);
        maxi = max(maxi, be[x]);//check if there exists child that cannot reach top
    }
    //check art pt (with parent)
    if((p==-1 && children_cnt>=2) || (p!=-1 && maxi>=dep[nd])){
        // cout<<"art pt: "<<nd<<'\n';
        art_pts++;
    }
    if(be[nd]>=dep[nd]){
        if(p!=-1 && conns >= dep[nd]){
            // cout<<"bridge: "<<nd<<'\n';
            bridges++;
        }
    }
    be[nd] = min(be[nd], conns);
    // cout<<nd<<' '<<dep[nd]<<' '<<be[nd]<<'\n';
}
void dfs2(int nd, int pc=1,int p=-1){//edge colouring
    for(pii nex:adjl[nd]){
        int x=nex.f;int id = nex.s;
        if(dep[x]==dep[nd]+1){//child
            if(be[x]<dep[nd]){
                cols[id]=pc;
            }else cols[id]=nex_col++;
            cnt[cols[id]]++;
            max_cnt = max(max_cnt, cnt[cols[id]]);
            dfs2(x,cols[id], nd);
        }else if(dep[x]!=dep[nd]-1 && dep[x]<dep[nd]){//back edge
            cols[id]=pc;
            cnt[cols[id]]++;
            max_cnt = max(max_cnt, cnt[cols[id]]);
        }
    }
}

void solve(){
    int n,m;
    cin>>n>>m;

    //init
    for(int i=1;i<=n;i++){
        adjl[i].clear();
        dep[i]=-1;
    }
    bridges=art_pts=0;nex_col=2;
    for(int i=1;i<=m;i++){
        cnt[i]=0;
    }max_cnt=0;

    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        adjl[a].eb(b,i);
        adjl[b].eb(a,i);
    }
    dep[1]=1;
    dfs(1);
    dfs2(1);
    int p= nex_col-1;
    int q= max_cnt;
    if(cnt[1]==0)p--;
    int g = __gcd(p,q);
    // g=1;
    // for(int i=0;i<m;i++)cout<<cols[i]<<' ';cout<<'\n';
    cout<<art_pts<<' '<<bridges<<' '<<p/g<<' '<<q/g<<'\n';
}

int32_t main() {
    ios_base::sync_with_stdio(false);cin.tie(0);
    int tc;
    cin>>tc;
    while(tc--){
        solve();
    }
}
/*
1
6 6
1 2
2 3
3 4
4 5
5 6
6 1

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 5640kb

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: 35ms
memory: 30040kb

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