Submission #747765

# Submission time Handle Problem Language Result Execution time Memory
747765 2023-05-24T16:14:13 Z 1075508020060209tc Duathlon (APIO18_duathlon) C++14
0 / 100
156 ms 48500 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long

int n;int m;
vector<int>e[300005];
vector<int>tr[300005];
vector<int>bke[300005];
vector<int>dwe[300005];
int sz[300005];int vis[300005];int dph[300005];int fa[300005];
int ans;
int ok;
void fdfs(int nw){
vis[nw]=1;
sz[nw]=1;
for(int i=0;i<e[nw].size();i++){
    int v=e[nw][i];
    if(vis[v]==0){
        fa[v]=nw;
        dph[v]=dph[nw]+1;
        tr[nw].push_back(v);
        fdfs(v);
        sz[nw]+=sz[v];
        continue;
    }
    if(v==fa[nw]){continue;}
    if(dph[v]<dph[nw]){
        bke[nw].push_back(v);
        dwe[v].push_back(nw);
    }
}
}


void dfs1(int nw,int rtsz){
//ans+=(rtsz-sz[nw])*(sz[nw]-1);
for(int i=0;i<tr[nw].size();i++){
    int v=tr[nw][i];
    dfs1(v,rtsz);
  //  ans+=sz[v]*(rtsz-1-sz[v]);
}
if(bke[nw].size()){ok=1;}
}





signed main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int a;int b;
        cin>>a>>b;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    ans=0;
    vector<int>rt;
    for(int i=1;i<=n;i++){
        if(vis[i]==0){
            rt.push_back(i);
            fdfs(i);
        }
    }
    for(int i=0;i<rt.size();i++){
        ok=0;
        dfs1(rt[i],sz[rt[i]]);
     //   cout<<ok<<" "<<sz[rt[i]]<<"\n";
        if(ok){
            ans+=(sz[rt[i]]*(sz[rt[i]]-1)*(sz[rt[i]]-2));
        }else{
            ans+=(sz[rt[i]]*(sz[rt[i]]-1)*(sz[rt[i]]-2)/6);
        }
    }






    cout<<ans<<endl;
}

Compilation message

count_triplets.cpp: In function 'void fdfs(long long int)':
count_triplets.cpp:17:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 | for(int i=0;i<e[nw].size();i++){
      |             ~^~~~~~~~~~~~~
count_triplets.cpp: In function 'void dfs1(long long int, long long int)':
count_triplets.cpp:38:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 | for(int i=0;i<tr[nw].size();i++){
      |             ~^~~~~~~~~~~~~~
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:67:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for(int i=0;i<rt.size();i++){
      |                 ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 28500 KB Output is correct
2 Correct 15 ms 28500 KB Output is correct
3 Correct 14 ms 28496 KB Output is correct
4 Correct 15 ms 28488 KB Output is correct
5 Correct 15 ms 28500 KB Output is correct
6 Correct 15 ms 28408 KB Output is correct
7 Incorrect 15 ms 28448 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 28500 KB Output is correct
2 Correct 15 ms 28500 KB Output is correct
3 Correct 14 ms 28496 KB Output is correct
4 Correct 15 ms 28488 KB Output is correct
5 Correct 15 ms 28500 KB Output is correct
6 Correct 15 ms 28408 KB Output is correct
7 Incorrect 15 ms 28448 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 132 ms 47240 KB Output is correct
2 Correct 156 ms 48500 KB Output is correct
3 Incorrect 147 ms 43992 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 28500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 138 ms 37228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 28488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 128 ms 37164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 28500 KB Output is correct
2 Correct 15 ms 28500 KB Output is correct
3 Correct 14 ms 28496 KB Output is correct
4 Correct 15 ms 28488 KB Output is correct
5 Correct 15 ms 28500 KB Output is correct
6 Correct 15 ms 28408 KB Output is correct
7 Incorrect 15 ms 28448 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 28500 KB Output is correct
2 Correct 15 ms 28500 KB Output is correct
3 Correct 14 ms 28496 KB Output is correct
4 Correct 15 ms 28488 KB Output is correct
5 Correct 15 ms 28500 KB Output is correct
6 Correct 15 ms 28408 KB Output is correct
7 Incorrect 15 ms 28448 KB Output isn't correct
8 Halted 0 ms 0 KB -