답안 #981556

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
981556 2024-05-13T10:28:12 Z dimashhh 철인 이종 경기 (APIO18_duathlon) C++17
31 / 100
64 ms 25428 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 2e5 + 5, MOD = 998244353;
typedef long double ld;

int n,m,tin[N],fup[N],timer;
bool vis[N];
vector<int> g[N];
void dfs(int v,int pr = -1){
    vis[v]=1;
    fup[v] = tin[v] = ++timer;
    for(int to:g[v]){
        if(to == pr) continue;
        if(!vis[to]){
            dfs(to,v);
            fup[v] = min(fup[v],fup[to]);
        }else{
            fup[v] = min(fup[v],tin[to]);
        }
    }
}
int mxc=0,c[N];
ll sz[N];
void paint(int v,int cl){
    c[v] = cl;
    sz[cl]++;
    for(int to:g[v]){
        if(!c[to]){
            if(fup[to] > tin[v]){
                mxc++;
                paint(to,mxc);
            }else{
                paint(to,cl);
            }
        }
    }
}
vector<int> G[N];
int P[N];
int get(int v){
    if(P[v] == v) return v;
    return P[v]= get(P[v]);
}
void merge(int a,int b){
    a = get(a);
    b = get(b);
    P[a] = b;
}
int sum[N];
void dfs2(int v,int pr = -1){
    sum[v] = sz[v];
    for(int to:G[v]){
        if(to == pr) continue;
        dfs2(to,v);
        sum[v] += sum[to];
    }
}
ll res = 0;
void dfs3(int v,int pr = -1,int S = 0){
    ll ss =0 ,ff = S - sum[v];
    for(int to:G[v]){
        if(to != pr){
            dfs3(to,v,S);
            ss += ff * 1ll * sum[to];
            ff += sum[to];
        }
    }
    ss *= 2;
    res += ss * 1ll * sz[v];
}
void test(){
    cin >> n >> m;
    for(int i = 1;i <= m;i++){
        int a,b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for(int i = 1;i <= n;i++){
        P[i] = i;
        if(!vis[i]){
            dfs(i);
        }
    }
    for(int i = 1;i <= n;i++){
        if(!c[i]){
            mxc++;
            paint(i,mxc);
        }
    }
    for(int i = 1;i <= n;i++){
        for(int to:g[i]){
            int x = c[i],y = c[to];
            if(get(x)!=get(y)){
                G[x].push_back(y);
                G[y].push_back(x);
                merge(x,y);
            }
        }
    }
    n = mxc;
    for(int i = 1;i <= n;i++) {
        vis[i]=0;
        res += sz[i] * (sz[i] - 1) * (sz[i] - 2);
    }
    ll A = 0;
//    for(int i = 1;i <= n;i++){
//        for(int j = 1;j <= n;j++){
//            if(i == j) continue;
//
//            A += sz[i] * sz[j] * (sz[j] - 1) - sz[j]+1;
//        }
//    }
    res += A*2;
    for(int i = 1;i <= n;i++){
        if(!sum[i]){
            dfs2(i);
            dfs3(i,-1,sum[i]);
        }
    }
    cout << res << '\n';
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int T = 1;
//    cin >> T;
    while (T--){
        test();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12632 KB Output is correct
2 Correct 4 ms 12636 KB Output is correct
3 Correct 4 ms 12720 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 3 ms 12636 KB Output is correct
6 Correct 3 ms 12636 KB Output is correct
7 Incorrect 3 ms 12636 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12632 KB Output is correct
2 Correct 4 ms 12636 KB Output is correct
3 Correct 4 ms 12720 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 3 ms 12636 KB Output is correct
6 Correct 3 ms 12636 KB Output is correct
7 Incorrect 3 ms 12636 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 24068 KB Output is correct
2 Correct 39 ms 24236 KB Output is correct
3 Correct 47 ms 22196 KB Output is correct
4 Correct 40 ms 23132 KB Output is correct
5 Correct 44 ms 20308 KB Output is correct
6 Correct 44 ms 21592 KB Output is correct
7 Correct 44 ms 20620 KB Output is correct
8 Correct 47 ms 20816 KB Output is correct
9 Correct 44 ms 19804 KB Output is correct
10 Correct 41 ms 19804 KB Output is correct
11 Correct 36 ms 18572 KB Output is correct
12 Correct 36 ms 18516 KB Output is correct
13 Correct 32 ms 18524 KB Output is correct
14 Correct 31 ms 18264 KB Output is correct
15 Correct 26 ms 18424 KB Output is correct
16 Correct 27 ms 18012 KB Output is correct
17 Correct 5 ms 14172 KB Output is correct
18 Correct 5 ms 14172 KB Output is correct
19 Correct 5 ms 14172 KB Output is correct
20 Correct 5 ms 14216 KB Output is correct
21 Correct 5 ms 14004 KB Output is correct
22 Correct 5 ms 14172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12632 KB Output is correct
2 Correct 3 ms 12636 KB Output is correct
3 Correct 3 ms 12636 KB Output is correct
4 Correct 3 ms 12892 KB Output is correct
5 Correct 3 ms 12892 KB Output is correct
6 Correct 3 ms 12636 KB Output is correct
7 Correct 3 ms 12892 KB Output is correct
8 Correct 3 ms 12636 KB Output is correct
9 Correct 3 ms 12728 KB Output is correct
10 Correct 4 ms 12636 KB Output is correct
11 Correct 3 ms 12636 KB Output is correct
12 Correct 3 ms 12740 KB Output is correct
13 Correct 3 ms 12636 KB Output is correct
14 Correct 3 ms 12636 KB Output is correct
15 Correct 3 ms 12632 KB Output is correct
16 Correct 4 ms 12636 KB Output is correct
17 Correct 3 ms 12636 KB Output is correct
18 Correct 3 ms 12636 KB Output is correct
19 Correct 3 ms 12636 KB Output is correct
20 Correct 3 ms 12636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 20644 KB Output is correct
2 Correct 50 ms 20560 KB Output is correct
3 Correct 55 ms 20560 KB Output is correct
4 Correct 59 ms 20660 KB Output is correct
5 Correct 51 ms 20560 KB Output is correct
6 Correct 60 ms 25428 KB Output is correct
7 Correct 57 ms 23632 KB Output is correct
8 Correct 54 ms 22868 KB Output is correct
9 Correct 64 ms 22168 KB Output is correct
10 Correct 55 ms 20540 KB Output is correct
11 Correct 51 ms 20564 KB Output is correct
12 Correct 50 ms 20816 KB Output is correct
13 Correct 52 ms 20628 KB Output is correct
14 Correct 45 ms 20308 KB Output is correct
15 Correct 39 ms 20076 KB Output is correct
16 Correct 26 ms 18844 KB Output is correct
17 Correct 33 ms 21540 KB Output is correct
18 Correct 34 ms 21348 KB Output is correct
19 Correct 35 ms 21708 KB Output is correct
20 Correct 40 ms 21340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12636 KB Output is correct
2 Correct 3 ms 12636 KB Output is correct
3 Incorrect 3 ms 12636 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 20564 KB Output is correct
2 Correct 51 ms 20308 KB Output is correct
3 Incorrect 56 ms 19232 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12632 KB Output is correct
2 Correct 4 ms 12636 KB Output is correct
3 Correct 4 ms 12720 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 3 ms 12636 KB Output is correct
6 Correct 3 ms 12636 KB Output is correct
7 Incorrect 3 ms 12636 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12632 KB Output is correct
2 Correct 4 ms 12636 KB Output is correct
3 Correct 4 ms 12720 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 3 ms 12636 KB Output is correct
6 Correct 3 ms 12636 KB Output is correct
7 Incorrect 3 ms 12636 KB Output isn't correct
8 Halted 0 ms 0 KB -