Submission #742860

# Submission time Handle Problem Language Result Execution time Memory
742860 2023-05-17T04:42:01 Z PixelCat Duathlon (APIO18_duathlon) C++14
0 / 100
77 ms 22896 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];
    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 Incorrect 4 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 19800 KB Output is correct
2 Correct 56 ms 19884 KB Output is correct
3 Incorrect 70 ms 17068 KB Output isn't correct
4 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 Correct 3 ms 5076 KB Output is correct
4 Correct 3 ms 5204 KB Output is correct
5 Correct 3 ms 5124 KB Output is correct
6 Correct 3 ms 5076 KB Output is correct
7 Correct 3 ms 5204 KB Output is correct
8 Correct 3 ms 5076 KB Output is correct
9 Correct 3 ms 5076 KB Output is correct
10 Incorrect 4 ms 5076 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 68 ms 16416 KB Output is correct
2 Correct 64 ms 16332 KB Output is correct
3 Correct 62 ms 16392 KB Output is correct
4 Correct 74 ms 16404 KB Output is correct
5 Correct 67 ms 16344 KB Output is correct
6 Correct 77 ms 22896 KB Output is correct
7 Correct 71 ms 19280 KB Output is correct
8 Correct 77 ms 18472 KB Output is correct
9 Correct 67 ms 17740 KB Output is correct
10 Incorrect 67 ms 15956 KB Output isn't correct
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 Incorrect 3 ms 5076 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 64 ms 16504 KB Output is correct
2 Correct 62 ms 16148 KB Output is correct
3 Incorrect 65 ms 14540 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -