답안 #260926

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
260926 2020-08-11T08:08:42 Z emanIaicepsa 철인 이종 경기 (APIO18_duathlon) C++14
31 / 100
192 ms 24568 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define vi vector<int>
#define pb emplace_back
#define fi first
#define se second
#define all(n) (n).begin(),(n).end()
#define mem(n,m) memset(n,m,sizeof(n))
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);
template<typename A> void _do(A x){cerr<<x<<'\n';}
template<typename A,typename ...B> void _do(A x,B ...y){cerr<<x<<", ";_do(y...);}

const int mxn = 100005;
ll C(ll x){
    return (x)*(x-1)*(x-2)/6*2;
}

ll P(ll x){
    return C(x)*3;
}

ll n,m;
vi E[mxn], E2[mxn];
ll siz[mxn], ans=0, l[mxn], d[mxn], bcc[mxn], bcc_siz[mxn], dfn, bccid, vis[mxn], rt[mxn];
stack<int> s;

void dfs(int x,int p){
    l[x] = d[x] = ++dfn;
    s.push(x);
    for(auto i:E[x]){
        if(i==p) continue;
        if(!d[i]){
            dfs(i,x);
            l[x] = min(l[x],l[i]);
        }
        else{
            l[x] = min(l[x],d[i]);
        }
    }
    if(l[x] == d[x]){
        bccid++;
        for(int i;i!=x;){
            i = s.top(); s.pop();
            bcc[i] = bccid;
        }
    }
}

void bcc_dfs(int x,int p,int anc){
    rt[x] = anc;
    siz[x] = bcc_siz[x];
    vis[x] = 1;
    for(auto i:E2[x]){
        if(i==p) continue;
        bcc_dfs(i,x,anc);
        siz[x] += siz[i];
    }
}

void bcc_dfs2(int x,int p,int anc){
    vis[x] = 1;
    for(auto i:E2[x]){
        if(i==p) continue;
        bcc_dfs2(i,x,anc);
        ans += siz[i] * (siz[anc] - siz[i] - bcc_siz[x]) * bcc_siz[x];
    }
    ans += (siz[x]-bcc_siz[x]) * (siz[anc]-siz[x]);
}

signed main(){
	IOS;
    cin>>n>>m;
    for(int i=1,a,b;i<=m;i++){
        cin>>a>>b;
        E[a].pb(b);
        E[b].pb(a);
    }


    for(int i=1;i<=n;i++) if(!d[i]) dfs(i,0);

    for(int i=1;i<=n;i++){
        //dbg(i, bcc[i]);
        bcc_siz[bcc[i]]++;
        for(auto j:E[i]){
            if(bcc[i] == bcc[j]) continue;
            E2[bcc[i]].pb(bcc[j]);
            E2[bcc[j]].pb(bcc[i]);
        }
    }

    for(int i=1;i<=bccid;i++){
        sort(all(E2[i]));
        E2[i].resize(unique(all(E2[i]))-E2[i].begin());
    }

    for(int i=1;i<=bccid;i++){
        if(!vis[i]){
            bcc_dfs(i,0,i);
        }
    }
//    for(int i=1;i<=bccid;i++){
//        dbg(i, siz[i]);
//    }
    mem(vis,0);
    for(int i=1;i<=bccid;i++){
        if(bcc_siz[i]>=3){
            ll x = bcc_siz[i];
            ans += P(x);
            ans += (x-1) * (x-1) * (siz[rt[i]] - x) * 2;
        }
        if(!vis[i]){
            bcc_dfs2(i,0,i);
        }
    }

    cout<<ans<<'\n';

}
/*
3 3
1 2
2 3
3 1

4 4
1 2
2 3
3 4
2 4

5 4
1 2
2 3
1 3
4 5
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5888 KB Output is correct
2 Correct 4 ms 5888 KB Output is correct
3 Correct 4 ms 5888 KB Output is correct
4 Correct 4 ms 5888 KB Output is correct
5 Correct 5 ms 5888 KB Output is correct
6 Correct 4 ms 5888 KB Output is correct
7 Incorrect 4 ms 5888 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5888 KB Output is correct
2 Correct 4 ms 5888 KB Output is correct
3 Correct 4 ms 5888 KB Output is correct
4 Correct 4 ms 5888 KB Output is correct
5 Correct 5 ms 5888 KB Output is correct
6 Correct 4 ms 5888 KB Output is correct
7 Incorrect 4 ms 5888 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 19524 KB Output is correct
2 Correct 93 ms 19908 KB Output is correct
3 Correct 130 ms 18296 KB Output is correct
4 Correct 103 ms 18936 KB Output is correct
5 Correct 114 ms 16120 KB Output is correct
6 Correct 124 ms 19192 KB Output is correct
7 Correct 132 ms 16504 KB Output is correct
8 Correct 121 ms 17784 KB Output is correct
9 Correct 110 ms 15736 KB Output is correct
10 Correct 104 ms 15972 KB Output is correct
11 Correct 94 ms 14840 KB Output is correct
12 Correct 94 ms 14728 KB Output is correct
13 Correct 89 ms 15056 KB Output is correct
14 Correct 84 ms 14712 KB Output is correct
15 Correct 66 ms 14968 KB Output is correct
16 Correct 72 ms 14584 KB Output is correct
17 Correct 11 ms 10496 KB Output is correct
18 Correct 11 ms 10496 KB Output is correct
19 Correct 11 ms 10496 KB Output is correct
20 Correct 10 ms 10496 KB Output is correct
21 Correct 10 ms 10496 KB Output is correct
22 Correct 10 ms 10496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 6016 KB Output is correct
2 Correct 5 ms 6016 KB Output is correct
3 Correct 5 ms 6016 KB Output is correct
4 Correct 5 ms 6016 KB Output is correct
5 Correct 5 ms 6016 KB Output is correct
6 Correct 5 ms 6016 KB Output is correct
7 Correct 4 ms 6016 KB Output is correct
8 Correct 5 ms 6016 KB Output is correct
9 Correct 6 ms 6016 KB Output is correct
10 Correct 5 ms 6016 KB Output is correct
11 Correct 5 ms 6016 KB Output is correct
12 Correct 6 ms 6016 KB Output is correct
13 Correct 5 ms 6016 KB Output is correct
14 Correct 5 ms 6016 KB Output is correct
15 Correct 5 ms 6016 KB Output is correct
16 Correct 5 ms 5888 KB Output is correct
17 Correct 4 ms 6016 KB Output is correct
18 Correct 6 ms 6016 KB Output is correct
19 Correct 6 ms 6016 KB Output is correct
20 Correct 5 ms 6048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 17640 KB Output is correct
2 Correct 130 ms 17656 KB Output is correct
3 Correct 127 ms 17656 KB Output is correct
4 Correct 127 ms 17528 KB Output is correct
5 Correct 139 ms 17528 KB Output is correct
6 Correct 158 ms 24568 KB Output is correct
7 Correct 165 ms 20284 KB Output is correct
8 Correct 161 ms 19448 KB Output is correct
9 Correct 192 ms 18808 KB Output is correct
10 Correct 147 ms 17656 KB Output is correct
11 Correct 169 ms 17648 KB Output is correct
12 Correct 151 ms 17528 KB Output is correct
13 Correct 150 ms 17612 KB Output is correct
14 Correct 140 ms 17348 KB Output is correct
15 Correct 121 ms 16888 KB Output is correct
16 Correct 81 ms 15224 KB Output is correct
17 Correct 122 ms 17900 KB Output is correct
18 Correct 101 ms 18028 KB Output is correct
19 Correct 113 ms 18016 KB Output is correct
20 Correct 106 ms 18164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 6016 KB Output is correct
2 Correct 5 ms 6016 KB Output is correct
3 Incorrect 5 ms 5888 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 160 ms 17644 KB Output is correct
2 Correct 162 ms 17400 KB Output is correct
3 Incorrect 139 ms 15480 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5888 KB Output is correct
2 Correct 4 ms 5888 KB Output is correct
3 Correct 4 ms 5888 KB Output is correct
4 Correct 4 ms 5888 KB Output is correct
5 Correct 5 ms 5888 KB Output is correct
6 Correct 4 ms 5888 KB Output is correct
7 Incorrect 4 ms 5888 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5888 KB Output is correct
2 Correct 4 ms 5888 KB Output is correct
3 Correct 4 ms 5888 KB Output is correct
4 Correct 4 ms 5888 KB Output is correct
5 Correct 5 ms 5888 KB Output is correct
6 Correct 4 ms 5888 KB Output is correct
7 Incorrect 4 ms 5888 KB Output isn't correct
8 Halted 0 ms 0 KB -