Submission #742859

# Submission time Handle Problem Language Result Execution time Memory
742859 2023-05-17T04:38:00 Z PixelCat Duathlon (APIO18_duathlon) C++14
0 / 100
103 ms 23692 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(i != p && 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 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 73 ms 18968 KB Output is correct
2 Correct 69 ms 19088 KB Output is correct
3 Incorrect 65 ms 17048 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5168 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 5168 KB Output is correct
6 Correct 4 ms 5164 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 66 ms 17088 KB Output is correct
2 Correct 66 ms 17064 KB Output is correct
3 Correct 67 ms 17124 KB Output is correct
4 Correct 76 ms 17104 KB Output is correct
5 Correct 66 ms 17156 KB Output is correct
6 Correct 73 ms 23692 KB Output is correct
7 Correct 74 ms 19492 KB Output is correct
8 Correct 75 ms 18880 KB Output is correct
9 Correct 70 ms 18212 KB Output is correct
10 Incorrect 66 ms 16764 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 5152 KB Output is correct
3 Incorrect 4 ms 5032 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 77 ms 17252 KB Output is correct
2 Correct 72 ms 16876 KB Output is correct
3 Incorrect 103 ms 15348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -