Submission #742258

# Submission time Handle Problem Language Result Execution time Memory
742258 2023-05-16T02:53:43 Z victor_gao Duathlon (APIO18_duathlon) C++17
0 / 100
165 ms 48832 KB
//#pragma GCC optimize("Ofast,unroll-loops,O3")
//#pragma GCC optimize("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma,tune=native")
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//#pragma pack(1)
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define int long long
#define pii pair<int,int>
#define x first
#define y second
#define N 100015
using namespace std;
//using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> order_multiset;
//typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> order_set;
int n,m,dfn[N],low[N],boss[N],sz[N],cont[N],nbcc=0,t=0,ans=0;
stack<int>st;
vector<int>g[N],bcc[N];
set<int>G[N];
map<int,int>cnt[N];
vector<pii>edge;
void tarjan(int p,int lp){
    dfn[p]=low[p]=++t;
    st.push(p);
    for (auto i:g[p]){
        if (!dfn[i]){
            tarjan(i,p);
            low[p]=min(low[p],low[i]);
        }
        else if (i!=lp&&dfn[i]<dfn[p])
            low[p]=min(low[p],dfn[i]);
    }
    if (dfn[p]==low[p]){
        nbcc++;
        for (int x=0;x!=p;st.pop()){
            x=st.top(); boss[x]=nbcc; cont[nbcc]++;
            bcc[nbcc].push_back(x);
        }
    }
}
void build(){
    for (auto [a,b]:edge){
        if (boss[a]!=boss[b]){
            G[boss[a]].insert(boss[b]);
            G[boss[b]].insert(boss[a]);
        }
    }
}
void dfs(int p,int lp){
    sz[p]=cont[p];
    for (auto i:G[p]){
        if (i!=lp){
            dfs(i,p);
            sz[p]+=sz[i];
        }
    }
}
void dfs1(int p,int lp){
    sz[p]+=sz[lp];
    int tans=0;
    for (auto i:G[p]){
        tans=(tans+(cont[p]-1)*sz[i]*2+(cont[p]-1)*(cont[p]-2)*sz[i]*2);
        tans=(tans+cont[p]*(sz[p]-cont[p]-sz[i])*sz[i]);
    }
    ans=(ans+tans);
    for (auto i:G[p]){
        if (i!=lp){
            sz[p]-=sz[i];
            dfs1(i,p);
            sz[p]+=sz[i];
        }
    }
    sz[p]-=sz[lp];
}
signed main(){
    fast
    cin>>n>>m;
    for (int i=1;i<=m;i++){
        int a,b; cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
        edge.push_back({a,b});
    }
    tarjan(1,0);
    build();
    dfs(1,0); dfs1(1,0);
   // cout<<ans<<'\n';
    for (int i=1;i<=nbcc;i++){
        ans=(ans+cont[i]*(cont[i]-1)*(cont[i]-2));
    }
    cout<<ans<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14440 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 7 ms 14440 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 7 ms 14332 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Incorrect 7 ms 14420 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14440 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 7 ms 14440 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 7 ms 14332 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Incorrect 7 ms 14420 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 68 ms 33464 KB Output is correct
2 Correct 61 ms 33504 KB Output is correct
3 Incorrect 51 ms 27400 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14664 KB Output is correct
2 Correct 9 ms 14676 KB Output is correct
3 Correct 9 ms 14560 KB Output is correct
4 Correct 8 ms 14676 KB Output is correct
5 Correct 8 ms 14632 KB Output is correct
6 Correct 8 ms 14684 KB Output is correct
7 Correct 8 ms 14676 KB Output is correct
8 Correct 8 ms 14676 KB Output is correct
9 Correct 8 ms 14676 KB Output is correct
10 Incorrect 9 ms 14548 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 151 ms 36088 KB Output is correct
2 Correct 121 ms 36720 KB Output is correct
3 Correct 165 ms 36792 KB Output is correct
4 Correct 132 ms 36912 KB Output is correct
5 Correct 123 ms 36772 KB Output is correct
6 Correct 133 ms 48832 KB Output is correct
7 Correct 157 ms 41076 KB Output is correct
8 Correct 135 ms 40004 KB Output is correct
9 Correct 126 ms 38812 KB Output is correct
10 Incorrect 92 ms 30608 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 14588 KB Output is correct
2 Correct 8 ms 14560 KB Output is correct
3 Incorrect 9 ms 14596 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 121 ms 36152 KB Output is correct
2 Correct 113 ms 36408 KB Output is correct
3 Incorrect 100 ms 33504 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14440 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 7 ms 14440 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 7 ms 14332 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Incorrect 7 ms 14420 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14440 KB Output is correct
2 Correct 8 ms 14420 KB Output is correct
3 Correct 7 ms 14440 KB Output is correct
4 Correct 7 ms 14420 KB Output is correct
5 Correct 7 ms 14332 KB Output is correct
6 Correct 7 ms 14420 KB Output is correct
7 Incorrect 7 ms 14420 KB Output isn't correct
8 Halted 0 ms 0 KB -