답안 #1033225

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1033225 2024-07-24T14:33:15 Z _8_8_ 철인 이종 경기 (APIO18_duathlon) C++17
23 / 100
100 ms 44512 KB
#include <bits/stdc++.h>
 
using namespace std;
    
typedef long long ll;
const int  N = 4e5 + 21, MOD = (int)1e9+7;
 
int n,m;

vector<vector<int>> bcc(vector<vector<int>> &g,vector<int> &sz){
    vector<bool> ap(n+1,0);
    vector<int> tin(n+1,0),up(n+1,0),id(n+1,0);
    vector<int> stk;
    vector<vector<int>> comps,G;
    function <void(int,int,int&)> dfs = [&](int v,int pr,int &t){
        tin[v] = up[v] = ++t;
        stk.push_back(v);
        int cc  =0;
        for(int to:g[v]){
            if(to == pr)continue;
            if(!tin[to]){
                dfs(to,v,t);
                cc++;
                up[v] = min(up[v],up[to]);
                if(up[to] >= tin[v]){
                    if(pr != -1){
                        ap[v] = 1;
                    }
                    comps.push_back({v});
                    while(comps.back().back() != to){
                        comps.back().push_back(stk.back());
                        stk.pop_back();
                    }  
                }
            }else{
                up[v] = min(up[v],tin[to]);
            }
        }
        if(pr == -1){
            ap[v] = (cc > 1);
        }
    };
    int timer = 0;
    for(int i = 1;i <= n;i++){
        if(!tin[i]){
            dfs(i,-1,timer);
        }
    }
    function<vector<vector<int>>()> build_tree = [&]() {
        vector<vector<int>> t(1);
        int it = 0;
        sz = vector<int> (1,0);
        for(int i = 1;i <= n;i++){
            if(ap[i]){
                id[i] = ++it;
                sz.push_back(1);
                sz[id[i]] = 1;
                t.push_back({});
            }
        }
        for(auto c:comps){
            it++;
            sz.push_back(0);
            t.push_back({});
            for(auto j:c){
                if(ap[j]){
                    t[id[j]].push_back(it);
                    t[it].push_back(id[j]);
                }else{
                    id[j] = it;
                    sz[it]++;
                }
            }
        }
        return t;
    };
    return build_tree();
}
vector<vector<int>> g(N),G;
ll calc(vector<int> &S){
    ll s = 0,d = 0,t = 0;
    for(auto i:S){
        t += i *1ll * d;
        d += s * 1ll * i;
        s += i;
    }
    return t;
}
int bf_n,nn = 0;
vector<int> sz;
bool vis[N];
ll ss[N];
void prec(int v,int pr = -1){
    vis[v] = 1;
    ss[v] += sz[v];
    for(int to:G[v]){
        if(to == pr)continue;
        prec(to,v);
        ss[v] += ss[to];
    }
}
ll res = 0;
void clac(int v,int pr = -1){
    ll c = sz[v] * 1ll * (sz[v] - 1);
    // res += c / 2 *1ll * (sz[v] - 2 + (ll)G[v].size());
    vector<ll> vals;
    for(int to:G[v]){
        if(to == pr){
            vals.push_back(nn-ss[v]);
            continue;
        }
        clac(to,v);
        vals.push_back(ss[to]);
    }
    ll D = 0,S = 0;
    for(ll i:vals){
        D += i * S;
        S += i;
        // cout << i << ' ';
    }
    // cout << '\n';
    res += D * 1ll * sz[v];
}
void test(){
    cin >> n >> m;
    for(int i = 1;i <= m;i++){
        int u,v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    G = bcc(g,sz);
    n = (int)G.size() - 1;
    for(int i = 1;i <= n;i++){
        if(!vis[i]){
            prec(i);
            nn = ss[i];
            clac(i);
        }
    }
    cout << res * 2 << '\n';
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(0);
    int t = 1; 
    // cin >> t;
    while(t--) {
        test();
    }
}

Compilation message

count_triplets.cpp: In function 'void clac(int, int)':
count_triplets.cpp:104:8: warning: unused variable 'c' [-Wunused-variable]
  104 |     ll c = sz[v] * 1ll * (sz[v] - 1);
      |        ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 9816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 9816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 30800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10072 KB Output is correct
2 Correct 4 ms 10072 KB Output is correct
3 Correct 5 ms 10076 KB Output is correct
4 Correct 4 ms 10076 KB Output is correct
5 Correct 4 ms 10112 KB Output is correct
6 Correct 5 ms 10032 KB Output is correct
7 Correct 5 ms 10076 KB Output is correct
8 Correct 5 ms 10076 KB Output is correct
9 Correct 5 ms 10076 KB Output is correct
10 Correct 5 ms 10076 KB Output is correct
11 Correct 5 ms 10076 KB Output is correct
12 Correct 5 ms 10076 KB Output is correct
13 Correct 5 ms 10076 KB Output is correct
14 Correct 5 ms 10076 KB Output is correct
15 Correct 6 ms 10076 KB Output is correct
16 Correct 4 ms 9820 KB Output is correct
17 Correct 4 ms 9820 KB Output is correct
18 Correct 4 ms 9816 KB Output is correct
19 Correct 4 ms 9820 KB Output is correct
20 Correct 4 ms 9880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 32252 KB Output is correct
2 Correct 74 ms 32000 KB Output is correct
3 Correct 68 ms 32004 KB Output is correct
4 Correct 69 ms 32004 KB Output is correct
5 Correct 86 ms 31988 KB Output is correct
6 Correct 100 ms 44512 KB Output is correct
7 Correct 85 ms 38460 KB Output is correct
8 Correct 80 ms 37436 KB Output is correct
9 Correct 84 ms 34428 KB Output is correct
10 Correct 77 ms 31968 KB Output is correct
11 Correct 90 ms 32004 KB Output is correct
12 Correct 66 ms 32004 KB Output is correct
13 Correct 67 ms 32056 KB Output is correct
14 Correct 61 ms 31492 KB Output is correct
15 Correct 53 ms 26624 KB Output is correct
16 Correct 37 ms 22284 KB Output is correct
17 Correct 43 ms 28016 KB Output is correct
18 Correct 43 ms 28156 KB Output is correct
19 Correct 44 ms 28088 KB Output is correct
20 Correct 43 ms 28160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10076 KB Output is correct
2 Correct 5 ms 9876 KB Output is correct
3 Incorrect 5 ms 10076 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 31992 KB Output is correct
2 Correct 69 ms 31488 KB Output is correct
3 Incorrect 71 ms 31236 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 9816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 9816 KB Output isn't correct
2 Halted 0 ms 0 KB -