답안 #111606

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
111606 2019-05-15T16:51:41 Z sealnot123 철인 이종 경기 (APIO18_duathlon) C++14
31 / 100
212 ms 27912 KB
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define ep emplace_back
#define sz(a) (int)(a).size()
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const int N=100050;
vector< vector<int> > comp; // bridge tree
vector<int> g[N],G[N],sta;
int t,art[N],visited[N],lowlink[N],mk[N],ncomp[N];
LL dp[2][N],ans=0;
void dfs(int u, int p){
    visited[u] = lowlink[u] = ++t;
    sta.pb(u);
    for(int e : g[u]){
        if(e==p) continue;
        if(!visited[e]){
            dfs(e, u);
            lowlink[u] = min(lowlink[u], lowlink[e]);
        }else{
            lowlink[u] = min(lowlink[u], visited[e]);
        }
    }
    if(lowlink[u] == visited[u]){
        int nw = comp.size();
        comp.pb({u});
        ncomp[u]=nw;
        while(sta.back()!=u){
            comp.back().pb(sta.back());
            ncomp[sta.back()]=nw;
            sta.pop_back();
        }
        sta.pop_back();
    }
}
void DFS(int u, int p){
    LL S = sz(comp[u]);
    for(int e : G[u]){
        if(e==p) continue;
        DFS(e,u);
        ans += dp[0][e]*dp[1][u];
        ans += dp[1][e]*dp[0][u];
        dp[0][u] += dp[0][e];
        dp[1][u] += dp[1][e] + dp[0][e]*S;
        ans += dp[0][e]*(S-1)*(S-1);
        ans += dp[1][e]*S;
    }
    dp[0][u] += S;
    dp[1][u] += (S-1)*(S-1);
//    printf("%lld %lld %lld %lld===\n",ans,S,dp[0][u],dp[1][u]);
}
int main(){
//    freopen("104","r",stdin);
//    freopen("104.sol","w",stdout);
    int n,m,i,j,a,b;
    scanf(" %d %d",&n,&m);
    for(i=1;i<=m;i++){
        scanf(" %d %d",&a,&b);
        g[a].pb(b); g[b].pb(a);
    }
    dfs(1,1);
    for(i=1;i<=n;i++){
        if(!visited[i]) dfs(i,i);
    }
    for(i=0;i<sz(comp);i++){
//        printf("#%d: ",i);
        for(int u : comp[i]){
//            printf("%d ",u);
            for(int e : g[u]){
                if(ncomp[e]!=i) mk[ncomp[e]]=1;
            }
        }
        for(int u : comp[i]){
            for(int e : g[u]){
                if(mk[ncomp[e]]) G[i].pb(ncomp[e]),mk[ncomp[e]]=0;
            }
        }
//        printf("\n");
    }
    for(i=0;i<sz(comp);i++){
        if(!dp[0][i]) DFS(i,i);
    }
    ans<<=1;
    for(i=0;i<sz(comp);i++){
        LL S = sz(comp[i]);
        ans += S*(S-1)*(S-2);
    }
    printf("%lld",ans);
    return 0;
}
/*
4 3
1 2
2 3
3 4

4 4
1 2
2 3
3 4
4 2
*/

Compilation message

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:58:15: warning: unused variable 'j' [-Wunused-variable]
     int n,m,i,j,a,b;
               ^
count_triplets.cpp:59: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:61:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %d %d",&a,&b);
         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4992 KB Output is correct
2 Correct 8 ms 4992 KB Output is correct
3 Correct 6 ms 4992 KB Output is correct
4 Correct 5 ms 4992 KB Output is correct
5 Correct 6 ms 4992 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Incorrect 6 ms 4992 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4992 KB Output is correct
2 Correct 8 ms 4992 KB Output is correct
3 Correct 6 ms 4992 KB Output is correct
4 Correct 5 ms 4992 KB Output is correct
5 Correct 6 ms 4992 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Incorrect 6 ms 4992 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 131 ms 19924 KB Output is correct
2 Correct 118 ms 19860 KB Output is correct
3 Correct 147 ms 19816 KB Output is correct
4 Correct 152 ms 19584 KB Output is correct
5 Correct 112 ms 16476 KB Output is correct
6 Correct 150 ms 19916 KB Output is correct
7 Correct 175 ms 17960 KB Output is correct
8 Correct 166 ms 18872 KB Output is correct
9 Correct 160 ms 16808 KB Output is correct
10 Correct 143 ms 16812 KB Output is correct
11 Correct 130 ms 15852 KB Output is correct
12 Correct 118 ms 15744 KB Output is correct
13 Correct 103 ms 16436 KB Output is correct
14 Correct 95 ms 16032 KB Output is correct
15 Correct 84 ms 16928 KB Output is correct
16 Correct 82 ms 16420 KB Output is correct
17 Correct 22 ms 13660 KB Output is correct
18 Correct 57 ms 13608 KB Output is correct
19 Correct 28 ms 13516 KB Output is correct
20 Correct 22 ms 13488 KB Output is correct
21 Correct 23 ms 13488 KB Output is correct
22 Correct 23 ms 13628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5244 KB Output is correct
2 Correct 10 ms 5248 KB Output is correct
3 Correct 8 ms 5248 KB Output is correct
4 Correct 8 ms 5248 KB Output is correct
5 Correct 10 ms 5248 KB Output is correct
6 Correct 7 ms 5248 KB Output is correct
7 Correct 7 ms 5248 KB Output is correct
8 Correct 6 ms 5248 KB Output is correct
9 Correct 6 ms 5248 KB Output is correct
10 Correct 6 ms 5248 KB Output is correct
11 Correct 7 ms 5248 KB Output is correct
12 Correct 6 ms 5120 KB Output is correct
13 Correct 6 ms 5120 KB Output is correct
14 Correct 7 ms 5216 KB Output is correct
15 Correct 21 ms 5248 KB Output is correct
16 Correct 7 ms 5248 KB Output is correct
17 Correct 7 ms 5248 KB Output is correct
18 Correct 6 ms 5248 KB Output is correct
19 Correct 7 ms 5248 KB Output is correct
20 Correct 6 ms 5248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 185 ms 20256 KB Output is correct
2 Correct 156 ms 20128 KB Output is correct
3 Correct 160 ms 20200 KB Output is correct
4 Correct 165 ms 20124 KB Output is correct
5 Correct 171 ms 20260 KB Output is correct
6 Correct 171 ms 27912 KB Output is correct
7 Correct 212 ms 23516 KB Output is correct
8 Correct 171 ms 22544 KB Output is correct
9 Correct 194 ms 21664 KB Output is correct
10 Correct 185 ms 20132 KB Output is correct
11 Correct 169 ms 20224 KB Output is correct
12 Correct 169 ms 20132 KB Output is correct
13 Correct 154 ms 20128 KB Output is correct
14 Correct 138 ms 19904 KB Output is correct
15 Correct 153 ms 19720 KB Output is correct
16 Correct 89 ms 18388 KB Output is correct
17 Correct 110 ms 21216 KB Output is correct
18 Correct 112 ms 21044 KB Output is correct
19 Correct 118 ms 21068 KB Output is correct
20 Correct 131 ms 20904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5248 KB Output is correct
2 Correct 9 ms 5120 KB Output is correct
3 Incorrect 7 ms 5248 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 190 ms 20104 KB Output is correct
2 Correct 185 ms 20092 KB Output is correct
3 Incorrect 175 ms 16536 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4992 KB Output is correct
2 Correct 8 ms 4992 KB Output is correct
3 Correct 6 ms 4992 KB Output is correct
4 Correct 5 ms 4992 KB Output is correct
5 Correct 6 ms 4992 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Incorrect 6 ms 4992 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4992 KB Output is correct
2 Correct 8 ms 4992 KB Output is correct
3 Correct 6 ms 4992 KB Output is correct
4 Correct 5 ms 4992 KB Output is correct
5 Correct 6 ms 4992 KB Output is correct
6 Correct 6 ms 5120 KB Output is correct
7 Incorrect 6 ms 4992 KB Output isn't correct
8 Halted 0 ms 0 KB -