Submission #1032802

# Submission time Handle Problem Language Result Execution time Memory
1032802 2024-07-24T08:58:19 Z _8_8_ Duathlon (APIO18_duathlon) C++17
0 / 100
65 ms 33136 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;
}
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);
    }
    int bf_n = n;
    vector<int> sz;
    G = bcc(g,sz);
    n = (int)G.size() - 1;
    ll res = calc(sz);
    for(int i = 1;i <= n;i++){
        ll val = sz[i] * 1ll * (sz[i] - 1),k = val / 2;
        val = val * 1ll * (bf_n - sz[i]);
        res += val;
        res += k * 1ll * (ll)G[i].size();
    }
    cout << res * 2 << '\n';
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(0);
    int t = 1; 
    // cin >> t;
    while(t--) {
        test();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9820 KB Output is correct
2 Incorrect 3 ms 9820 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9820 KB Output is correct
2 Incorrect 3 ms 9820 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 30800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 9868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 64 ms 33136 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 10072 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 65 ms 33032 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9820 KB Output is correct
2 Incorrect 3 ms 9820 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 9820 KB Output is correct
2 Incorrect 3 ms 9820 KB Output isn't correct
3 Halted 0 ms 0 KB -