답안 #261546

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
261546 2020-08-11T20:51:57 Z Rouge_Hugo 철인 이종 경기 (APIO18_duathlon) C++14
0 / 100
177 ms 24648 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];
int cnt=1,num[N],low[N],bridge[N],b[N],par[N],vis[N],sz[N],bo[N];
pair<int,int>a[N];
int t=0;
void dfs (int x,int p)
{
    low[x]=num[x]=++t;
    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)
{
    for(auto it:v1[x])
    {
        if(it==p)continue;
        solve(it,x);
        sz[x]+=sz[it];
    }
    sz[x]+=bo[x];
}
ll go (int x,int p,ll up)
{

    sz[x]-=bo[x];
    if(bo[x]>=3)
        re+=bo[x]*(bo[x]-1)*(bo[x]-2);
    re+=2*up*bo[x]*sz[x];
    if(bo[x]>2)
    {
        re+=(up)*((bo[x])-1)*((bo[x])-2)*2;
        re+=(sz[x])*(bo[x]-1)*(bo[x]-2)*2;
    }
    re+=(bo[x]-1)*up*2;
    re+=(bo[x]-1)*(sz[x])*2;
    for(auto it:v1[x])
    {
        if(it==p)continue;
        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});
    }
    dfs(1,0);
    int root=2;
    int mx=0;
    for(int i=1; i<n+1; i++)
    {
        szz=0;
        if (!vis[i])
        {
            szz=0;
            dfs1(i,-1);
            bo[i]=szz;
            cnt++;
        }
    }
    memset (vis,0,sizeof vis);
    dfs2(1,0);
    solve(1,0);re=0;
    go(1,0,0);
    cout<<re;
}

Compilation message

count_triplets.cpp: In function 'long long int go(int, int, long long int)':
count_triplets.cpp:85:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:99:9: warning: unused variable 'root' [-Wunused-variable]
     int root=2;
         ^~~~
count_triplets.cpp:100:9: warning: unused variable 'mx' [-Wunused-variable]
     int mx=0;
         ^~
count_triplets.cpp:89: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:93:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 10496 KB Output is correct
2 Correct 8 ms 10496 KB Output is correct
3 Correct 8 ms 10496 KB Output is correct
4 Correct 8 ms 10496 KB Output is correct
5 Correct 8 ms 10496 KB Output is correct
6 Correct 9 ms 10496 KB Output is correct
7 Incorrect 7 ms 10496 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 10496 KB Output is correct
2 Correct 8 ms 10496 KB Output is correct
3 Correct 8 ms 10496 KB Output is correct
4 Correct 8 ms 10496 KB Output is correct
5 Correct 8 ms 10496 KB Output is correct
6 Correct 9 ms 10496 KB Output is correct
7 Incorrect 7 ms 10496 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 127 ms 24648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 10624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 166 ms 21924 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 10624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 177 ms 21880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 10496 KB Output is correct
2 Correct 8 ms 10496 KB Output is correct
3 Correct 8 ms 10496 KB Output is correct
4 Correct 8 ms 10496 KB Output is correct
5 Correct 8 ms 10496 KB Output is correct
6 Correct 9 ms 10496 KB Output is correct
7 Incorrect 7 ms 10496 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 10496 KB Output is correct
2 Correct 8 ms 10496 KB Output is correct
3 Correct 8 ms 10496 KB Output is correct
4 Correct 8 ms 10496 KB Output is correct
5 Correct 8 ms 10496 KB Output is correct
6 Correct 9 ms 10496 KB Output is correct
7 Incorrect 7 ms 10496 KB Output isn't correct
8 Halted 0 ms 0 KB -