Submission #132973

# Submission time Handle Problem Language Result Execution time Memory
132973 2019-07-20T03:16:31 Z ae04071 Duathlon (APIO18_duathlon) C++11
31 / 100
162 ms 28932 KB
#include <bits/stdc++.h>
using namespace std;

int n,m,cut[100001],dfn[100001],low[100001],o,dn;
int bsz[200001];
vector<int> adj[100001],badj[200001];
stack<int> stk;

int ts;
void addEdge(int u,int v) {
    badj[u].push_back(v);
    badj[v].push_back(u);
}
void dfs(int cur,int p) {
    ts++;
    dfn[cur] = low[cur] = ++dn;
    stk.push(cur);
    for(auto &it:adj[cur]) if(it!=p) {
        if(dfn[it]) low[cur] = min(low[cur],low[it]);
        else {
            dfs(it,cur);
            low[cur] = min(low[cur],low[it]);
            if(low[it]>=dfn[cur]) {
                ++n;
                cut[cur] = 1;
                while(!stk.empty()) {
                    int v=stk.top();
                    bsz[n]++;
                    if(cut[v]) addEdge(n, v);
                    if(v==cur) break;
                    stk.pop();
                }
            }
        }
    }
}

long long ans;
int sz[200001];
int cal_dfs(int cur,int p) {
    sz[cur] = bsz[cur];
    for(auto &it:badj[cur]) if(it!=p) sz[cur] += cal_dfs(it,cur);
    sz[cur] -= ((int)badj[cur].size() - (p>0) - (cur<=o));

    if(cur>o) {
        for(auto &it:badj[cur]) if(it!=p) ans += 1ll*(bsz[cur]-1)*sz[it]*(sz[it]-1);
        ans += 1ll*(bsz[cur]-1)*(ts-sz[cur]+1)*(ts-sz[cur]);
    }
    return sz[cur];
}

int main() {
    scanf("%d%d",&n,&m);
    for(int i=0,u,v;i<m;i++) {
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    o = n;

    long long ret = 0;
    for(int i=1;i<=o;i++) if(!dfn[i]) {
        ts=0; ans=0;
        dfs(i,0);
        
        cal_dfs(i, 0);
        ret += 1ll*ts*(ts-1)*(ts-2) - ans;
    }
    printf("%lld\n",ret);
    
    return 0;
}

Compilation message

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:53: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:55:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&u,&v);
         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7544 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 9 ms 7416 KB Output is correct
5 Correct 8 ms 7416 KB Output is correct
6 Correct 8 ms 7416 KB Output is correct
7 Incorrect 8 ms 7416 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7544 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 9 ms 7416 KB Output is correct
5 Correct 8 ms 7416 KB Output is correct
6 Correct 8 ms 7416 KB Output is correct
7 Incorrect 8 ms 7416 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 91 ms 22520 KB Output is correct
2 Correct 98 ms 22392 KB Output is correct
3 Correct 123 ms 23288 KB Output is correct
4 Correct 119 ms 22464 KB Output is correct
5 Correct 120 ms 19784 KB Output is correct
6 Correct 134 ms 22524 KB Output is correct
7 Correct 135 ms 20600 KB Output is correct
8 Correct 133 ms 21260 KB Output is correct
9 Correct 137 ms 19064 KB Output is correct
10 Correct 111 ms 19064 KB Output is correct
11 Correct 96 ms 16504 KB Output is correct
12 Correct 94 ms 16312 KB Output is correct
13 Correct 100 ms 16248 KB Output is correct
14 Correct 87 ms 15964 KB Output is correct
15 Correct 67 ms 15352 KB Output is correct
16 Correct 68 ms 14956 KB Output is correct
17 Correct 12 ms 9336 KB Output is correct
18 Correct 12 ms 9336 KB Output is correct
19 Correct 12 ms 9216 KB Output is correct
20 Correct 12 ms 9208 KB Output is correct
21 Correct 12 ms 9128 KB Output is correct
22 Correct 12 ms 9208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7544 KB Output is correct
2 Correct 9 ms 7544 KB Output is correct
3 Correct 9 ms 7544 KB Output is correct
4 Correct 9 ms 7672 KB Output is correct
5 Correct 9 ms 7544 KB Output is correct
6 Correct 9 ms 7544 KB Output is correct
7 Correct 9 ms 7544 KB Output is correct
8 Correct 9 ms 7544 KB Output is correct
9 Correct 9 ms 7544 KB Output is correct
10 Correct 9 ms 7544 KB Output is correct
11 Correct 9 ms 7544 KB Output is correct
12 Correct 9 ms 7544 KB Output is correct
13 Correct 9 ms 7544 KB Output is correct
14 Correct 9 ms 7548 KB Output is correct
15 Correct 9 ms 7544 KB Output is correct
16 Correct 9 ms 7544 KB Output is correct
17 Correct 9 ms 7544 KB Output is correct
18 Correct 9 ms 7544 KB Output is correct
19 Correct 9 ms 7460 KB Output is correct
20 Correct 9 ms 7544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 128 ms 19064 KB Output is correct
2 Correct 132 ms 19180 KB Output is correct
3 Correct 138 ms 19064 KB Output is correct
4 Correct 125 ms 19064 KB Output is correct
5 Correct 123 ms 18936 KB Output is correct
6 Correct 162 ms 28932 KB Output is correct
7 Correct 147 ms 25232 KB Output is correct
8 Correct 155 ms 23672 KB Output is correct
9 Correct 157 ms 22236 KB Output is correct
10 Correct 144 ms 18988 KB Output is correct
11 Correct 128 ms 19100 KB Output is correct
12 Correct 135 ms 19192 KB Output is correct
13 Correct 129 ms 18968 KB Output is correct
14 Correct 115 ms 18640 KB Output is correct
15 Correct 104 ms 17912 KB Output is correct
16 Correct 68 ms 15392 KB Output is correct
17 Correct 74 ms 17268 KB Output is correct
18 Correct 77 ms 17312 KB Output is correct
19 Correct 77 ms 17472 KB Output is correct
20 Correct 116 ms 17272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7544 KB Output is correct
2 Correct 9 ms 7544 KB Output is correct
3 Incorrect 9 ms 7544 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 134 ms 18992 KB Output is correct
2 Correct 129 ms 19312 KB Output is correct
3 Incorrect 142 ms 18632 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7544 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 9 ms 7416 KB Output is correct
5 Correct 8 ms 7416 KB Output is correct
6 Correct 8 ms 7416 KB Output is correct
7 Incorrect 8 ms 7416 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7544 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 9 ms 7416 KB Output is correct
5 Correct 8 ms 7416 KB Output is correct
6 Correct 8 ms 7416 KB Output is correct
7 Incorrect 8 ms 7416 KB Output isn't correct
8 Halted 0 ms 0 KB -