Submission #733625

# Submission time Handle Problem Language Result Execution time Memory
733625 2023-05-01T05:16:14 Z bin9638 Duathlon (APIO18_duathlon) C++17
0 / 100
125 ms 31240 KB
#include <bits/stdc++.h>

using namespace std;

#define N 200010
#define ll long long
#define fs first
#define sc second
#define ii pair<int,int>
#define pb push_back

ll ans=0;
int times,num[N],low[N],n,m,ktr[N],dem,sz[N],child[N];
vector<int>g[N],edge[N];
stack<int>st;

void visit(int u,int p)
{
    num[u]=low[u]=++times;
    for(auto v:g[u])
        if(v!=p)
        {
            if(num[v]!=0)
            {
                low[u]=min(low[u],num[v]);
            }else
            {
                st.push(u);
                visit(v,u);
                low[u]=min(low[u],low[v]);
                if(low[v]>=num[u])
                {
                    int k;
                    dem++;
                    do{
                        k=st.top();
                        st.pop();

                        if(ktr[k]!=dem)
                        {
                             sz[dem]++;
                            ktr[k]=dem;
                            edge[dem].pb(k);
                            edge[k].pb(dem);
                        }
                    }while(k!=u);
                }
            }
        }
    st.push(u);
}

void build(int u,int p)
{
    child[u]=(u<=n);
    //cout<<u<<" "<<child[u]<<endl;
    for(auto v:edge[u])
        if(v!=p)
        {
            build(v,u);
            child[u]+=child[v];
        }
}

void DFS(int u,int p)
{
    if(u<=n)
    {
        int sum=n-1;
        for(auto v:edge[u])
            if(v!=p)
            {
                sum-=child[v];
                ans+=1ll*sum*child[v];
            //    cout<<sum<<" "<<child[v]<<endl;
            }
    }else
    {
        int sum=n;
        for(auto v:edge[u])
            if(v!=p)
            {
                sum-=child[v];
                ans+=1ll*sum*child[v]*(sz[u]-2);
               // cout<<u<<" "<<sum<<" "<<child[v]<<" "<<sz[u]<<endl;
            }
    }
    //cout<<u<<" "<<ans*2<<endl;
    for(auto v:edge[u])
        if(v!=p)
            DFS(v,u);
}

int main()
{
    #ifdef SKY
    freopen("A.inp","r",stdin);
    freopen("A.out","w",stdout);
    #endif // SKY
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int u,v;
        cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dem=n;
    for(int i=1;i<=n;i++)
        if(num[i]==0)
            visit(i,0);
    //cout<<dem<<endl;
    build(1,0);
  // cout<<child[1]<<endl;
    DFS(1,0);
    cout<<ans*2;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 68 ms 27752 KB Output is correct
2 Correct 86 ms 29092 KB Output is correct
3 Incorrect 94 ms 25472 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9812 KB Output is correct
2 Correct 6 ms 9812 KB Output is correct
3 Correct 6 ms 9812 KB Output is correct
4 Correct 8 ms 9940 KB Output is correct
5 Correct 7 ms 9852 KB Output is correct
6 Correct 8 ms 9928 KB Output is correct
7 Correct 6 ms 9948 KB Output is correct
8 Correct 7 ms 9896 KB Output is correct
9 Correct 6 ms 9812 KB Output is correct
10 Incorrect 6 ms 9776 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 102 ms 21612 KB Output is correct
2 Correct 94 ms 22828 KB Output is correct
3 Correct 98 ms 22928 KB Output is correct
4 Correct 99 ms 22892 KB Output is correct
5 Correct 118 ms 23004 KB Output is correct
6 Correct 125 ms 31240 KB Output is correct
7 Correct 99 ms 28376 KB Output is correct
8 Correct 104 ms 26968 KB Output is correct
9 Correct 110 ms 25448 KB Output is correct
10 Incorrect 97 ms 22824 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9812 KB Output is correct
2 Correct 6 ms 9748 KB Output is correct
3 Correct 5 ms 9812 KB Output is correct
4 Correct 6 ms 9812 KB Output is correct
5 Correct 5 ms 9812 KB Output is correct
6 Correct 5 ms 9812 KB Output is correct
7 Correct 5 ms 9812 KB Output is correct
8 Correct 5 ms 9812 KB Output is correct
9 Correct 6 ms 9812 KB Output is correct
10 Correct 5 ms 9812 KB Output is correct
11 Correct 5 ms 9812 KB Output is correct
12 Correct 6 ms 9868 KB Output is correct
13 Correct 5 ms 9812 KB Output is correct
14 Correct 5 ms 9812 KB Output is correct
15 Correct 6 ms 9812 KB Output is correct
16 Incorrect 7 ms 9812 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 93 ms 21580 KB Output is correct
2 Correct 86 ms 22756 KB Output is correct
3 Correct 93 ms 22336 KB Output is correct
4 Correct 94 ms 21452 KB Output is correct
5 Correct 89 ms 20616 KB Output is correct
6 Correct 98 ms 20240 KB Output is correct
7 Correct 82 ms 19972 KB Output is correct
8 Correct 69 ms 19732 KB Output is correct
9 Correct 77 ms 19668 KB Output is correct
10 Correct 78 ms 19608 KB Output is correct
11 Correct 67 ms 19556 KB Output is correct
12 Correct 70 ms 19580 KB Output is correct
13 Correct 65 ms 19660 KB Output is correct
14 Correct 68 ms 21972 KB Output is correct
15 Correct 105 ms 28096 KB Output is correct
16 Correct 107 ms 26300 KB Output is correct
17 Correct 101 ms 26804 KB Output is correct
18 Correct 98 ms 25164 KB Output is correct
19 Incorrect 95 ms 21524 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 9684 KB Output isn't correct
2 Halted 0 ms 0 KB -