Submission #401436

# Submission time Handle Problem Language Result Execution time Memory
401436 2021-05-10T09:23:30 Z Hazem Duathlon (APIO18_duathlon) C++14
31 / 100
109 ms 21528 KB
#include <bits/stdc++.h>
using namespace std;
 
#define LL long long
#define F first
#define S second
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>

const int N = 2e5+10;
const int M = 200;
const LL INF = 1e9;
const LL LINF = 1e14;
const LL MOD = 1e9+7;
const double PI = 3.141592653589793;

vector<int>adj[N];
LL sizes[N],depth[N],mx[N],mn[N],n,m,par[N];
bool vis[N];

int dfs1(int i,int pre){

    par[i] = pre;
    sizes[i] = vis[i] = 1;
    for(auto x:adj[i])
        if(!vis[x])
            depth[x] = depth[i]+1,sizes[i] += dfs1(x,i);

        else if(x!=pre){
            int cur = i;
            while(depth[cur]>=depth[x])mx[cur] = x,mn[cur] = i,cur = par[cur];
        }

    return sizes[i];
}

LL C(LL n,LL k){

    LL ret = 1,d = 1;
    for(int i=n;i>=n-k+1;i--)
        ret = ret*i,d *= n-i+1;

    return ret/d;
}

LL dfs(int i,int pre,int sz){

    LL ret = 0;
    for(auto x:adj[i])
        if(depth[x]==depth[i]+1)
            ret += dfs(x,i,sz);
    
    LL cur = sz-1;
    for(auto x:adj[i]){
        
        if(depth[x]==depth[i]+1||x==pre){
            LL v = 0;
            if(x==pre)v = sz-sizes[i];
            else v = sizes[x];
            ret += (cur-v)*v;
        }
        else if(depth[x]<depth[i]){
            LL len = depth[i]-depth[x]+1;
            ret += C(len,3)*4;
        }
    }

        if(mx[i]&&mx[i]!=i){
            LL len = -depth[mx[i]]+depth[i]-1;
            ret += len*(sz-sizes[mx[i]])*2;
        }

        if(mn[i]&&mn[i]!=i){
            LL len = depth[mn[i]]-depth[i]-1;
            ret += len*(sizes[mn[i]]-1)*2;
        }

    return ret;
}

int main(){

    //freopen("out.txt","w",stdout);
    //freopen("out.txt","r",stdin);

    scanf("%d%d",&n,&m);

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

    depth[0] = -1;
    LL ans = 0;
    for(int i=1;i<=n;i++)
        if(!vis[i]){
            int sz = dfs1(i,0);
            ans += dfs(i,0,sz);
        }

    printf("%lld\n",ans);
}   

Compilation message

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:86:13: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   86 |     scanf("%d%d",&n,&m);
      |            ~^    ~~
      |             |    |
      |             int* long long int*
      |            %lld
count_triplets.cpp:86:15: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
   86 |     scanf("%d%d",&n,&m);
      |              ~^     ~~
      |               |     |
      |               int*  long long int*
      |              %lld
count_triplets.cpp:86:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   86 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
count_triplets.cpp:90:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   90 |         scanf("%d%d",&u,&v);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 96 ms 21508 KB Output is correct
2 Correct 107 ms 21528 KB Output is correct
3 Correct 91 ms 16840 KB Output is correct
4 Correct 93 ms 19072 KB Output is correct
5 Correct 100 ms 15212 KB Output is correct
6 Correct 109 ms 15184 KB Output is correct
7 Correct 82 ms 14020 KB Output is correct
8 Correct 89 ms 14676 KB Output is correct
9 Correct 87 ms 13112 KB Output is correct
10 Correct 88 ms 13836 KB Output is correct
11 Correct 68 ms 12100 KB Output is correct
12 Correct 61 ms 11988 KB Output is correct
13 Correct 52 ms 11972 KB Output is correct
14 Correct 51 ms 11900 KB Output is correct
15 Correct 50 ms 11452 KB Output is correct
16 Correct 47 ms 11376 KB Output is correct
17 Correct 6 ms 7116 KB Output is correct
18 Correct 6 ms 7116 KB Output is correct
19 Correct 8 ms 6988 KB Output is correct
20 Correct 6 ms 7088 KB Output is correct
21 Correct 6 ms 6988 KB Output is correct
22 Correct 6 ms 6860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5068 KB Output is correct
2 Correct 4 ms 5068 KB Output is correct
3 Correct 4 ms 5068 KB Output is correct
4 Correct 4 ms 5068 KB Output is correct
5 Correct 4 ms 5068 KB Output is correct
6 Correct 4 ms 5068 KB Output is correct
7 Correct 4 ms 5068 KB Output is correct
8 Correct 4 ms 5068 KB Output is correct
9 Correct 5 ms 5068 KB Output is correct
10 Correct 4 ms 5068 KB Output is correct
11 Correct 4 ms 5068 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 4 ms 5068 KB Output is correct
14 Correct 4 ms 5068 KB Output is correct
15 Correct 4 ms 5068 KB Output is correct
16 Correct 4 ms 5068 KB Output is correct
17 Correct 4 ms 5068 KB Output is correct
18 Correct 4 ms 5068 KB Output is correct
19 Correct 4 ms 5068 KB Output is correct
20 Correct 4 ms 5068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 10684 KB Output is correct
2 Correct 75 ms 10668 KB Output is correct
3 Correct 70 ms 10648 KB Output is correct
4 Correct 70 ms 10688 KB Output is correct
5 Correct 73 ms 10592 KB Output is correct
6 Correct 101 ms 15700 KB Output is correct
7 Correct 84 ms 13940 KB Output is correct
8 Correct 89 ms 13016 KB Output is correct
9 Correct 82 ms 12228 KB Output is correct
10 Correct 83 ms 10692 KB Output is correct
11 Correct 69 ms 10640 KB Output is correct
12 Correct 67 ms 10696 KB Output is correct
13 Correct 75 ms 10760 KB Output is correct
14 Correct 57 ms 10576 KB Output is correct
15 Correct 56 ms 10436 KB Output is correct
16 Correct 41 ms 9792 KB Output is correct
17 Correct 46 ms 10920 KB Output is correct
18 Correct 57 ms 10868 KB Output is correct
19 Correct 48 ms 10876 KB Output is correct
20 Correct 49 ms 10984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5068 KB Output is correct
2 Correct 4 ms 5068 KB Output is correct
3 Incorrect 4 ms 5104 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 73 ms 10688 KB Output is correct
2 Correct 73 ms 10532 KB Output is correct
3 Incorrect 98 ms 12192 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -