Submission #698643

# Submission time Handle Problem Language Result Execution time Memory
698643 2023-02-14T06:38:23 Z vjudge1 Duathlon (APIO18_duathlon) C++17
66 / 100
110 ms 27960 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];
bool c_vis[maxn];
int ct=0;
int tot;
vector<pair<int,int> > b[maxn];
int sz[maxn];
void dfs(int u,int p=-1) {
    tot++;
    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) {
    c_vis[u]=true;
    if(br[u]) cur=u;
    for(auto v:g[u]) {
        if(!c_vis[v]) {
            if(br[v]) {
                b[cur].push_back({u,v});
                b[v].push_back({v,cur});
            }
            dfs_2(v,cur);
        }
    }
}
void dfs_3(int u,int p=-1) {
    cnt[u]=sz[u];
    for(auto v:b[u]) {
        if(v.second!=p) {
            cnt[u]-=sz[v.second];
            dfs_3(v.second,u);
        }
    }
}
long long ans=0;
int mp[maxn];
void dfs_4(int u,int p=-1) {
    int pc=n-sz[u];
    vector<pair<int,int> > szs;
    for(auto v:b[u]) {
        if(v.second!=p) {
            mp[v.first]+=sz[v.second];
        }
        else {
            mp[v.first]+=(tot-sz[u]);
        }
    }
    for(auto v:b[u]) {
        if(v.second!=p) {
            szs.push_back({sz[v.second],mp[v.first]});
        }
        else {
            szs.push_back({tot-sz[u],mp[v.first]});
        }
    }
    for(auto v:b[u]) {
        mp[v.first]=0;
    }
    ans = ans+1ll*cnt[u]*(cnt[u]-1)*(cnt[u]-2);
    //cout<<u<<" "<<ans<<endl;
    for(auto c:szs) {
        //cout<<"\t"<<c.first<<" "<<c.second<<endl;
        int s=c.first;
        int a=tot-c.second-cnt[u];
        if(cnt[u]>=2) {
            ans=ans+2ll*(cnt[u]-1)*(cnt[u]-2)*s;
            ans=ans+2ll*(cnt[u]-1)*s;
        }
        //cout<<u<<" "<<ans<<endl;
        ans=ans+1ll*(cnt[u]-1)*s*a;
        ans=ans+1ll*s*(tot-s-cnt[u]);
    }
    //cout<<u<<" "<<ans<<endl;
    for(auto v:b[u]) {
        if(v.second!=p) dfs_4(v.second,u);
    }
}
/*int brute() {
    for(int c=1;c<=n;c++) {
        dfs_5(c);
    }
}*/
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);
    }
    for(int u=1;u<=n;u++) {
        if(!vis[u]) {
            tot=0;
            dfs(u);
            dfs_2(u,u);
            dfs_3(u,u);
            dfs_4(u,u);
        }
    }
    printf("%lld",ans);
    return 0;
}

Compilation message

count_triplets.cpp: In function 'void dfs_4(int, int)':
count_triplets.cpp:62:9: warning: unused variable 'pc' [-Wunused-variable]
   62 |     int pc=n-sz[u];
      |         ^~
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:108:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  108 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
count_triplets.cpp:111:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |         scanf("%d %d",&u,&v);
      |         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 4 ms 9684 KB Output is correct
4 Correct 4 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Incorrect 4 ms 9684 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 4 ms 9684 KB Output is correct
4 Correct 4 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Incorrect 4 ms 9684 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 69 ms 25552 KB Output is correct
2 Correct 73 ms 25552 KB Output is correct
3 Correct 91 ms 24168 KB Output is correct
4 Correct 84 ms 26116 KB Output is correct
5 Correct 83 ms 22308 KB Output is correct
6 Correct 90 ms 24124 KB Output is correct
7 Correct 107 ms 21952 KB Output is correct
8 Correct 92 ms 22020 KB Output is correct
9 Correct 84 ms 20280 KB Output is correct
10 Correct 87 ms 20668 KB Output is correct
11 Correct 66 ms 18184 KB Output is correct
12 Correct 75 ms 18020 KB Output is correct
13 Correct 57 ms 17996 KB Output is correct
14 Correct 57 ms 17828 KB Output is correct
15 Correct 50 ms 17408 KB Output is correct
16 Correct 46 ms 17148 KB Output is correct
17 Correct 8 ms 12244 KB Output is correct
18 Correct 8 ms 12292 KB Output is correct
19 Correct 8 ms 12116 KB Output is correct
20 Correct 8 ms 12228 KB Output is correct
21 Correct 8 ms 12160 KB Output is correct
22 Correct 8 ms 12116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9812 KB Output is correct
2 Correct 5 ms 9872 KB Output is correct
3 Correct 5 ms 9812 KB Output is correct
4 Correct 6 ms 9940 KB Output is correct
5 Correct 5 ms 9948 KB Output is correct
6 Correct 5 ms 9812 KB Output is correct
7 Correct 5 ms 9940 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 5 ms 9812 KB Output is correct
10 Correct 5 ms 9812 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 6 ms 9812 KB Output is correct
13 Correct 5 ms 9812 KB Output is correct
14 Correct 5 ms 9812 KB Output is correct
15 Correct 5 ms 9868 KB Output is correct
16 Correct 6 ms 9740 KB Output is correct
17 Correct 5 ms 9812 KB Output is correct
18 Correct 6 ms 9788 KB Output is correct
19 Correct 5 ms 9812 KB Output is correct
20 Correct 5 ms 9812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 19372 KB Output is correct
2 Correct 85 ms 19364 KB Output is correct
3 Correct 87 ms 19344 KB Output is correct
4 Correct 83 ms 19336 KB Output is correct
5 Correct 96 ms 19428 KB Output is correct
6 Correct 106 ms 27960 KB Output is correct
7 Correct 107 ms 25428 KB Output is correct
8 Correct 101 ms 23924 KB Output is correct
9 Correct 98 ms 22320 KB Output is correct
10 Correct 98 ms 19332 KB Output is correct
11 Correct 86 ms 20588 KB Output is correct
12 Correct 90 ms 20600 KB Output is correct
13 Correct 93 ms 20600 KB Output is correct
14 Correct 77 ms 20176 KB Output is correct
15 Correct 77 ms 19876 KB Output is correct
16 Correct 48 ms 17752 KB Output is correct
17 Correct 60 ms 22128 KB Output is correct
18 Correct 59 ms 22208 KB Output is correct
19 Correct 61 ms 22352 KB Output is correct
20 Correct 65 ms 21960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9812 KB Output is correct
2 Correct 6 ms 9864 KB Output is correct
3 Correct 5 ms 9812 KB Output is correct
4 Correct 5 ms 9812 KB Output is correct
5 Correct 5 ms 9812 KB Output is correct
6 Correct 5 ms 9812 KB Output is correct
7 Correct 5 ms 9812 KB Output is correct
8 Correct 5 ms 9812 KB Output is correct
9 Correct 5 ms 9816 KB Output is correct
10 Correct 6 ms 9812 KB Output is correct
11 Correct 5 ms 9812 KB Output is correct
12 Correct 5 ms 9812 KB Output is correct
13 Correct 5 ms 9848 KB Output is correct
14 Correct 5 ms 9812 KB Output is correct
15 Correct 5 ms 9812 KB Output is correct
16 Correct 5 ms 9848 KB Output is correct
17 Correct 5 ms 9812 KB Output is correct
18 Correct 5 ms 9812 KB Output is correct
19 Correct 6 ms 9740 KB Output is correct
20 Correct 5 ms 9812 KB Output is correct
21 Correct 6 ms 9868 KB Output is correct
22 Correct 6 ms 9812 KB Output is correct
23 Correct 5 ms 9872 KB Output is correct
24 Correct 5 ms 9876 KB Output is correct
25 Correct 4 ms 9740 KB Output is correct
26 Correct 5 ms 9740 KB Output is correct
27 Correct 5 ms 9732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 19272 KB Output is correct
2 Correct 88 ms 19116 KB Output is correct
3 Correct 86 ms 18004 KB Output is correct
4 Correct 80 ms 16988 KB Output is correct
5 Correct 72 ms 16204 KB Output is correct
6 Correct 67 ms 15948 KB Output is correct
7 Correct 69 ms 15964 KB Output is correct
8 Correct 64 ms 15760 KB Output is correct
9 Correct 70 ms 15820 KB Output is correct
10 Correct 71 ms 15944 KB Output is correct
11 Correct 64 ms 15760 KB Output is correct
12 Correct 57 ms 15992 KB Output is correct
13 Correct 61 ms 15932 KB Output is correct
14 Correct 66 ms 17896 KB Output is correct
15 Correct 110 ms 23488 KB Output is correct
16 Correct 104 ms 21844 KB Output is correct
17 Correct 100 ms 22320 KB Output is correct
18 Correct 106 ms 20832 KB Output is correct
19 Correct 81 ms 17284 KB Output is correct
20 Correct 86 ms 18536 KB Output is correct
21 Correct 101 ms 18476 KB Output is correct
22 Correct 75 ms 18104 KB Output is correct
23 Correct 72 ms 17680 KB Output is correct
24 Correct 77 ms 20176 KB Output is correct
25 Correct 93 ms 20228 KB Output is correct
26 Correct 76 ms 19460 KB Output is correct
27 Correct 80 ms 19404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 4 ms 9684 KB Output is correct
4 Correct 4 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Incorrect 4 ms 9684 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 4 ms 9684 KB Output is correct
4 Correct 4 ms 9684 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Incorrect 4 ms 9684 KB Output isn't correct
9 Halted 0 ms 0 KB -