Submission #742862

# Submission time Handle Problem Language Result Execution time Memory
742862 2023-05-17T04:45:43 Z PixelCat Duathlon (APIO18_duathlon) C++14
0 / 100
83 ms 40148 KB
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;

const int MAXN = 100010;

vector<int> adj[MAXN];
vector<int> bcc[MAXN];
int par[MAXN];
int dep[MAXN];
int id[MAXN];
int siz[MAXN];
int sum[MAXN];
int cur_bcc = 0;

void dfs_bcc(int n, int p, int d) {
    par[n] = p;
    dep[n] = d;
    for(auto &i:adj[n]) if(i != p) {
        if(!par[i]) {
            // tree edge
            dfs_bcc(i, n, d + 1);
        } else if(dep[i] < dep[n]) {
            // back edge
            cur_bcc++;
            int t = n;
            while(true) {
                id[t] = cur_bcc;
                if(t == i) break;
                t = par[t];
            }
        }
    }
    if(!id[n]) id[n] = ++cur_bcc;
    for(auto &i:adj[n]) if(dep[i] > dep[n] && id[i] != id[n]) {
        bcc[id[i]].eb(id[n]);
        bcc[id[n]].eb(id[i]);
    }
    siz[id[n]]++;
}

void dfs_siz(int n, int p) {
    sum[n] = siz[n];
    assert(siz[n] == 1);
    for(auto &i:bcc[n]) if(i != p) {
        // assert(!siz[i]);
        dfs_siz(i, n);
        sum[n] += sum[i];
    }
}

int ans;
#define C(x) ((x) * ((x) - 1))
void dfs_ans(int n, int p, int tot_n) {
    int t = C(tot_n - 1) * siz[n];
    for(auto &i:bcc[n]) {
        int s = sum[i];
        if(i == p) s = tot_n - sum[n];
        t -= C(s + 1) * (siz[n] - 1) + C(s);

        if(i != p) dfs_ans(i, n, tot_n);
    }
    ans += t;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // =^-w-^= nya
    int n, m; cin >> n >> m;
    while(m--) {
        int a, b; cin >> a >> b;
        adj[a].eb(b);
        adj[b].eb(a);
    }
    ans = 0;
    For(i, 1, n) if(!par[i]) {
        For(j, 1, cur_bcc) {
            bcc[j].clear();
            siz[j] = 0;
        }
        dfs_bcc(i, i, 1);
        dfs_siz(1, 1);
        dfs_ans(1, 1, sum[1]);

        // cout << cur_bcc << "\n";
        // For(j, 1, cur_bcc) {
        //     cout << j << " = " << siz[j] << ", " << sum[j] << ":";
        //     for(auto &k:bcc[j]) cout << " " << k;
        //     cout << "\n";
        // }
        // cout << flush;
    }
    cout << ans << "\n";
    return 0;
}

/*

4 3
1 2
2 3
3 4

4 4
1 2
2 3
3 4
4 2

*/
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 10068 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 10068 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 67 ms 40148 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5052 KB Output is correct
2 Correct 4 ms 5076 KB Output is correct
3 Correct 3 ms 5076 KB Output is correct
4 Correct 3 ms 5204 KB Output is correct
5 Correct 4 ms 5116 KB Output is correct
6 Correct 4 ms 5076 KB Output is correct
7 Correct 4 ms 5204 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Runtime error 7 ms 10196 KB Execution killed with signal 6
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 73 ms 16336 KB Output is correct
2 Correct 82 ms 16388 KB Output is correct
3 Correct 79 ms 16304 KB Output is correct
4 Correct 61 ms 16332 KB Output is correct
5 Correct 62 ms 16392 KB Output is correct
6 Correct 79 ms 22904 KB Output is correct
7 Correct 72 ms 19312 KB Output is correct
8 Correct 81 ms 18452 KB Output is correct
9 Correct 74 ms 17716 KB Output is correct
10 Runtime error 73 ms 32356 KB Execution killed with signal 6
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5076 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Runtime error 10 ms 10196 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 74 ms 16332 KB Output is correct
2 Correct 83 ms 16072 KB Output is correct
3 Runtime error 83 ms 28532 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 10068 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 10068 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -