Submission #261655

# Submission time Handle Problem Language Result Execution time Memory
261655 2020-08-11T23:39:19 Z Rouge_Hugo Duathlon (APIO18_duathlon) C++14
31 / 100
198 ms 29304 KB
#include<bits/stdc++.h>
#define fi first
#define ll long long
using namespace std;
int n,m;
ll re=0;
int szz=0;
const int N=200009;
vector<pair<int,int>>v[N];
vector<int>v1[N];
ll cnt=1,t[N],num[N],low[N],bridge[N],b[N],par[N],vis[N],sz[N],bo[N];
pair<int,int>a[N];
int tt=0;
void dfs (int x,int p)
{
    vis[x]=1;
    low[x]=num[x]=++tt;
    for(auto it:v[x])
    {
        if (num[it.first]==0)
            dfs(it.first,x);
        if (num[x]<low[it.first])
            bridge[it.second]=1;
        if (it.first!=p)
            low[x]=min(low[x],low[it.first]);
    }
}
void dfs1(int x,int p)
{
    vis[x]=1;
    par[x]=cnt;
    szz++;
    for(auto it:v[x])
    {
        if(it.fi==p)continue;
        if (!vis[it.first]&&bridge[it.second]==0)
        {
            dfs1(it.first,x);
        }
    }
}
void dfs2(int x,int p)
{
    vis[x]=1;
    for(auto it:v[x])
    {
        if(it.fi==p)continue;
        if (!vis[it.first])
            dfs2(it.first,x);
        if (bridge[it.second]==1)
        {
            v1[par[x]].push_back(par[it.first]);
            v1[par[it.first]].push_back(par[x]);
        }
    }
}
void solve(int x,int p)
{
    vis[x]=1;
    for(auto it:v1[x])
    {
        if(it==p)continue;
        solve(it,x);
        sz[x]+=sz[it];
    }
    sz[x]+=bo[x];
}
void go (int x,int p,ll up)
{
    vis[x]=1;
    sz[x]-=bo[x];
    if(bo[x]>=3)
        re+=bo[x]*(bo[x]-1)*(bo[x]-2);
    re+=2*up*bo[x]*sz[x];
    re+=(up)*((bo[x])-1)*((bo[x])-1)*2;
    re+=(sz[x])*(bo[x]-1)*(bo[x]-1)*2;
    for(auto it:v1[x])
    {
        if(it==p)continue;
        re+=2*t[x]*sz[it]*bo[x];
        t[x]+=sz[it];
        go(it,x,up+bo[x]+sz[x]-sz[it]);
    }
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    scanf("%d %d", &n, &m);
    int x,y;
    for(int i=0; i<m; i++)
    {
        scanf("%d %d", &x, &y);
        a[i]= {x,y};
        v[x].push_back({y,i});
        v[y].push_back({x,i});
    }
    memset (vis,0,sizeof vis);
    for(int i=1;i<n+1;i++)
    {
        if(vis[i])continue;
        dfs(i,-1);
    }
    memset (vis,0,sizeof vis);
    for(int i=1; i<n+1; i++)
    {
        if (!vis[i])
        {
            szz=0;
            dfs1(i,-1);
            bo[cnt]=szz;
            cnt++;
        }
    }
    memset (vis,0,sizeof vis);
    for(int i=1;i<n+1;i++)
    {
        if(vis[i])continue;
        dfs2(i,-1);
    }
    memset (vis,0,sizeof vis);
    for(int i=1;i<cnt;i++)
    {
        if(vis[i])continue;
        solve(i,0);
    }
    re=0;
    memset (vis,0,sizeof vis);
    for(int i=1;i<cnt;i++)
    {
        if(vis[i])continue;
        go(i,0,0);
    }
    cout<<re;
}

Compilation message

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:88:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
count_triplets.cpp:92:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11392 KB Output is correct
2 Correct 8 ms 11392 KB Output is correct
3 Correct 8 ms 11392 KB Output is correct
4 Correct 8 ms 11392 KB Output is correct
5 Correct 8 ms 11392 KB Output is correct
6 Correct 8 ms 11392 KB Output is correct
7 Incorrect 10 ms 11392 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11392 KB Output is correct
2 Correct 8 ms 11392 KB Output is correct
3 Correct 8 ms 11392 KB Output is correct
4 Correct 8 ms 11392 KB Output is correct
5 Correct 8 ms 11392 KB Output is correct
6 Correct 8 ms 11392 KB Output is correct
7 Incorrect 10 ms 11392 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 136 ms 27384 KB Output is correct
2 Correct 134 ms 27384 KB Output is correct
3 Correct 156 ms 26232 KB Output is correct
4 Correct 126 ms 28024 KB Output is correct
5 Correct 193 ms 24568 KB Output is correct
6 Correct 132 ms 25848 KB Output is correct
7 Correct 140 ms 24824 KB Output is correct
8 Correct 172 ms 25592 KB Output is correct
9 Correct 133 ms 23928 KB Output is correct
10 Correct 138 ms 24116 KB Output is correct
11 Correct 113 ms 22264 KB Output is correct
12 Correct 108 ms 22136 KB Output is correct
13 Correct 101 ms 22264 KB Output is correct
14 Correct 96 ms 22008 KB Output is correct
15 Correct 78 ms 21624 KB Output is correct
16 Correct 75 ms 21368 KB Output is correct
17 Correct 14 ms 15744 KB Output is correct
18 Correct 14 ms 15744 KB Output is correct
19 Correct 17 ms 15616 KB Output is correct
20 Correct 14 ms 15616 KB Output is correct
21 Correct 14 ms 15616 KB Output is correct
22 Correct 14 ms 15616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 11520 KB Output is correct
2 Correct 9 ms 11532 KB Output is correct
3 Correct 9 ms 11520 KB Output is correct
4 Correct 9 ms 11520 KB Output is correct
5 Correct 9 ms 11520 KB Output is correct
6 Correct 9 ms 11520 KB Output is correct
7 Correct 9 ms 11520 KB Output is correct
8 Correct 9 ms 11520 KB Output is correct
9 Correct 9 ms 11520 KB Output is correct
10 Correct 9 ms 11520 KB Output is correct
11 Correct 11 ms 11520 KB Output is correct
12 Correct 9 ms 11520 KB Output is correct
13 Correct 9 ms 11520 KB Output is correct
14 Correct 9 ms 11520 KB Output is correct
15 Correct 9 ms 11520 KB Output is correct
16 Correct 8 ms 11392 KB Output is correct
17 Correct 9 ms 11520 KB Output is correct
18 Correct 9 ms 11520 KB Output is correct
19 Correct 9 ms 11520 KB Output is correct
20 Correct 9 ms 11520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 177 ms 24952 KB Output is correct
2 Correct 153 ms 24952 KB Output is correct
3 Correct 160 ms 24952 KB Output is correct
4 Correct 158 ms 24952 KB Output is correct
5 Correct 165 ms 24952 KB Output is correct
6 Correct 185 ms 29304 KB Output is correct
7 Correct 176 ms 28024 KB Output is correct
8 Correct 198 ms 27128 KB Output is correct
9 Correct 163 ms 26360 KB Output is correct
10 Correct 147 ms 24956 KB Output is correct
11 Correct 168 ms 24936 KB Output is correct
12 Correct 140 ms 24952 KB Output is correct
13 Correct 148 ms 24908 KB Output is correct
14 Correct 157 ms 24448 KB Output is correct
15 Correct 123 ms 24056 KB Output is correct
16 Correct 82 ms 22008 KB Output is correct
17 Correct 102 ms 24680 KB Output is correct
18 Correct 97 ms 24604 KB Output is correct
19 Correct 103 ms 24800 KB Output is correct
20 Correct 96 ms 24680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 11520 KB Output is correct
2 Correct 9 ms 11520 KB Output is correct
3 Incorrect 9 ms 11520 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 146 ms 25080 KB Output is correct
2 Correct 154 ms 24824 KB Output is correct
3 Incorrect 170 ms 23416 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11392 KB Output is correct
2 Correct 8 ms 11392 KB Output is correct
3 Correct 8 ms 11392 KB Output is correct
4 Correct 8 ms 11392 KB Output is correct
5 Correct 8 ms 11392 KB Output is correct
6 Correct 8 ms 11392 KB Output is correct
7 Incorrect 10 ms 11392 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 11392 KB Output is correct
2 Correct 8 ms 11392 KB Output is correct
3 Correct 8 ms 11392 KB Output is correct
4 Correct 8 ms 11392 KB Output is correct
5 Correct 8 ms 11392 KB Output is correct
6 Correct 8 ms 11392 KB Output is correct
7 Incorrect 10 ms 11392 KB Output isn't correct
8 Halted 0 ms 0 KB -