답안 #698630

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
698630 2023-02-14T05:59:58 Z vjudge1 철인 이종 경기 (APIO18_duathlon) C++17
0 / 100
102 ms 27084 KB
#include<bits/stdc++.h>
#define maxn 200500
using namespace std;
int n,m;
vector<int> g[maxn];
bool vis[maxn];
int disc[maxn];
int low[maxn];
bool br[maxn];
int par[maxn];
int cnt[maxn];
int ct=0;
vector<int> b[maxn];
int sz[maxn];
void dfs(int u,int p=-1) {
    vis[u]=true;
    disc[u]=low[u]=ct++;
    sz[u]=1;
    for(auto v:g[u]) {
        if(!vis[v]) {
            dfs(v,u);
            sz[u]+=sz[v];
            par[v]=u;
            low[u]=min(low[u],low[v]);
            if(low[v]>disc[u]) {
                br[v]=true;
            }
        }
        else {
            if(v!=p) low[u]=min(low[u],disc[v]);
        }
    }
}
void dfs_2(int u,int cur=1) {
    vis[u]=true;
    if(br[u]) cur=u;
    for(auto v:g[u]) {
        if(!vis[v]) {
            if(br[v]) b[cur].push_back(v);
            dfs_2(v,cur);
        }
    }
}
void dfs_3(int u) {
    cnt[u]=sz[u];
    for(auto v:b[u]) {
        cnt[u]-=sz[v];
        dfs_3(v);
    }
}
long long ans=0;
void dfs_4(int u) {
    int pc=n-sz[u];
    vector<int> szs;
    if(pc!=0) szs.push_back(pc);
    for(auto v:b[u]) szs.push_back(sz[v]);
    ans = ans+1ll*cnt[u]*(cnt[u]-1)*(cnt[u]-2);
    for(auto s:szs) {
        if(cnt[u]>=2) {
            ans=ans+2ll*(cnt[u]-1)*(cnt[u]-2)*s;
            ans=ans+2ll*(cnt[u]-1)*s;
        }
        ans=ans+1ll*cnt[u]*s*(n-s-cnt[u]);
    }
    for(auto v:b[u]) dfs_4(v);
}
int main() {
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++) {
        int u,v;
        scanf("%d %d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1);
    for(int i=1;i<=n;i++) vis[i]=false;
    dfs_2(1);
    dfs_3(1);
    dfs_4(1);
    printf("%lld",ans);
    return 0;
}

Compilation message

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:68:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
count_triplets.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         scanf("%d %d",&u,&v);
      |         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 9812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 9812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 23532 KB Output is correct
2 Correct 70 ms 23564 KB Output is correct
3 Incorrect 57 ms 19660 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9796 KB Output is correct
2 Correct 5 ms 9736 KB Output is correct
3 Correct 6 ms 9812 KB Output is correct
4 Correct 6 ms 9940 KB Output is correct
5 Correct 6 ms 9812 KB Output is correct
6 Correct 6 ms 9812 KB Output is correct
7 Correct 6 ms 9852 KB Output is correct
8 Correct 5 ms 9812 KB Output is correct
9 Correct 6 ms 9812 KB Output is correct
10 Incorrect 5 ms 9812 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 17916 KB Output is correct
2 Correct 77 ms 17988 KB Output is correct
3 Correct 91 ms 17916 KB Output is correct
4 Correct 73 ms 17924 KB Output is correct
5 Correct 75 ms 17948 KB Output is correct
6 Correct 102 ms 27084 KB Output is correct
7 Correct 89 ms 23684 KB Output is correct
8 Correct 95 ms 22476 KB Output is correct
9 Correct 84 ms 20868 KB Output is correct
10 Incorrect 57 ms 17296 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9812 KB Output is correct
2 Correct 6 ms 9736 KB Output is correct
3 Incorrect 5 ms 9812 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 17956 KB Output is correct
2 Correct 87 ms 18296 KB Output is correct
3 Incorrect 80 ms 17776 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 9812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 9812 KB Output isn't correct
2 Halted 0 ms 0 KB -