Submission #679119

# Submission time Handle Problem Language Result Execution time Memory
679119 2023-01-07T13:41:23 Z PoonYaPat Duathlon (APIO18_duathlon) C++14
0 / 100
1000 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n,m,disc[100001],low[100001],sz[200001],cnt,bcc_cnt;
vector<int> adj[100001],bcc[200001];
ll ans,N;

stack<int> st;

void tarjan(int x, int par) {
    st.push(x);
    low[x]=disc[x]=++cnt;
    ++N;

    for (auto s : adj[x]) {
        if (s==par) continue;
        if (disc[s]) low[x]=min(low[x],disc[s]);
        else {
            tarjan(s,x);
            low[x]=min(low[x],low[s]);

            if (low[s]>=disc[x]) {
                ++bcc_cnt;
                bcc[x].push_back(N+bcc_cnt);

                int h=0;
                while (st.top()!=x) {
                    ++h;
                    assert(h<200005);
                    bcc[N+bcc_cnt].push_back(st.top());
                    st.pop();
                }
            }
        }
    }
}

void dfs(int x) {
    sz[x]= x>n ? 0 : 1;
    for (auto s : bcc[x]) {
        dfs(s);
        sz[x]+=sz[s];
        if (x>n) ans-=bcc[x].size()*sz[s]*(sz[s]-1);
    }
    if (x>n) ans-=bcc[x].size()*(N-sz[x])*(N-sz[x]-1);
}


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    for (int i=0; i<m; ++i) {
        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    for (int i=1; i<=n; ++i) {
        if (!disc[i]) {
            N=0;
            tarjan(i,0);
            ans+=N*(N-1)*(N-2);
            dfs(i);
        }
    }

    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 437 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 437 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 51 ms 22896 KB Output is correct
2 Correct 62 ms 22936 KB Output is correct
3 Execution timed out 1093 ms 17848 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 659 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 766 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 519 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 859 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 437 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 437 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -