Submission #1111620

# Submission time Handle Problem Language Result Execution time Memory
1111620 2024-11-12T11:00:05 Z Pioneer Duathlon (APIO18_duathlon) C++17
0 / 100
77 ms 42944 KB
#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")

#define ll long long
#define int ll
#define all(v) v.begin(),v.end()
#define sz(s) ((int)s.size())
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound

using namespace std;

const ll inf=1e18;
const int MAX=2e5+10;
const int mod=1e9+7;

int binpow(int a,int n){
    if(!n)return 1;
    if(n%2==1)return a*binpow(a,n-1)%mod;
    int k=binpow(a,n/2);
    return k*k%mod;
}

int n,m;
vector<int> g[MAX];
int tin[MAX],timer;
int fup[MAX];
bool use[MAX],cutPoint[MAX];
stack<int> st;
vector<int> ver[MAX];
int cmp[MAX],cnt;

void dfs(int v,int p=-1){
    st.push(v);
    tin[v]=fup[v]=++timer;
    use[v]=1;
    int children=0;
    for(auto to:g[v]){
        if(to==p)continue;
        if(!use[to]){
            children++;
            dfs(to,v);
            fup[v]=min(fup[v],fup[to]);
            if(fup[to]>=tin[v]){
                cutPoint[v]=(p!=-1);
                ver[++cnt].pb(v);
                while(ver[cnt].back()!=to){
                    ver[cnt].pb(st.top());
                    st.pop();
                }
            }
        }
        else fup[v]=min(fup[v],tin[to]);
    }
    if(p==-1&&children>1){
        cutPoint[v]=1;
    }
}

int ans;
int zs[MAX];
vector<vector<int>> t;

void calc(int v,int p=-1){
    use[v]=1;
    int in=zs[v];
    ans+=in*(in-1)*(in-2);
    ans+=2*in*(in-1)*(n-in);
    if(in>=2)ans+=sz(t[v])*in*(in-1);
    // cout<<v<<" "<<zs[v]<<"\n";
    // cout<<v<<" "<<2*in*(in-1)*(n-in)<<"\n";
    for(auto to:t[v]){
        if(to==p)continue;
        calc(to,v);
        zs[v]+=zs[to];
    }
    // cout<<v<<" "<<n-zs[v]<<" "<<zs[v]-in<<" "<<in<<"\n";
    ans+=(n-zs[v])*(zs[v]-in)*in;
    for(auto to:t[v]){
        if(to==p)continue;
        // cout<<v<<" "<<zs[to]<<" "<<n-zs[to]-in<<" "<<in<<"\n";
        ans+=zs[to]*(n-zs[to]-in)*in;
    }
}

void bct(){
    for(int i=1;i<=n;i++){
        if(!use[i])dfs(i);
    }
    int ck=0;
    for(int i=1;i<=n;i++){
        if(cutPoint[i]){
            zs[ck]=1;
            cmp[i]=ck++;
            t.pb({});
        }
    }
    // cout<<cnt<<" "<<cutPoint[1]<<"\n";
    for(int i=1;i<=cnt;i++){
        t.pb({});
        for(int v:ver[i]){
            if(!cutPoint[v]){
                cmp[v]=ck;
                zs[ck]++;
            }
            else{
                t[cmp[v]].pb(ck);
                t[ck].pb(cmp[v]);
            }
        }
        ck++;
    }
    // for(int i=0;i<sz(t);i++){
    //     cout<<zs[i]<<" ";
    // }
    // cout<<"\n";
    for(int i=0;i<sz(t);i++){
        sort(all(t[i]));
        t[i].erase(unique(all(t[i])),t[i].end());
    }
    memset(use,0,sizeof(use));
    for(int i=0;i<sz(t);i++)if(!use[i])calc(i);
}

void solve(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        int a,b;
        cin>>a>>b;
        g[a].pb(b);
        g[b].pb(a);
    }
    bct();
    // cout<<n*(n-1)*(n-2)/3<<"\n";
    cout<<ans<<"\n";
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)solve();
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 12112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 12112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 28364 KB Output is correct
2 Correct 39 ms 28356 KB Output is correct
3 Incorrect 58 ms 31856 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12368 KB Output is correct
2 Correct 4 ms 12308 KB Output is correct
3 Correct 4 ms 12368 KB Output is correct
4 Correct 3 ms 12368 KB Output is correct
5 Correct 3 ms 12368 KB Output is correct
6 Correct 4 ms 12368 KB Output is correct
7 Correct 3 ms 12368 KB Output is correct
8 Correct 4 ms 12368 KB Output is correct
9 Correct 3 ms 12368 KB Output is correct
10 Incorrect 3 ms 12356 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 63 ms 33464 KB Output is correct
2 Correct 59 ms 33536 KB Output is correct
3 Correct 63 ms 33508 KB Output is correct
4 Correct 61 ms 33524 KB Output is correct
5 Correct 71 ms 33472 KB Output is correct
6 Correct 77 ms 42944 KB Output is correct
7 Correct 72 ms 39860 KB Output is correct
8 Correct 69 ms 37300 KB Output is correct
9 Correct 67 ms 35264 KB Output is correct
10 Incorrect 69 ms 33464 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12368 KB Output is correct
2 Correct 3 ms 12368 KB Output is correct
3 Incorrect 4 ms 12368 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 66 ms 33468 KB Output is correct
2 Correct 67 ms 32884 KB Output is correct
3 Incorrect 57 ms 28600 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 12112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 12112 KB Output isn't correct
2 Halted 0 ms 0 KB -