Submission #747729

# Submission time Handle Problem Language Result Execution time Memory
747729 2023-05-24T15:16:37 Z 1075508020060209tc Duathlon (APIO18_duathlon) C++14
23 / 100
1000 ms 47200 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;

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]);
}
}

int bv;
pair<int,int> dfs2(int nw,int rtsz){
pair<int,int>ret={0,0};
for(int i=0;i<tr[nw].size();i++){
    int v=tr[nw][i];
    pair<int,int>vl=dfs2(v,rtsz);
    if(vl.first){
        ret=vl;
        ans+=(sz[v]-vl.first)*vl.first*2;
    }
}
if(bke[nw].size()){
    ret={sz[nw],bke[nw][0]};
    //bv=bke[nw][0];
}
if(dwe[nw].size()){
    ret={0,0};
}



if(ret.first){

    int vv=nw;
    while(fa[vv]!=ret.second){
        vv=fa[vv];
    }
    ans+=(rtsz-sz[vv])*(sz[vv]-sz[nw]) *2;
}


//cout<<nw<<" "<<ret<<endl;
return ret;
}



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++){
        dfs1(rt[i],sz[rt[i]]);
        dfs2(rt[i],sz[rt[i]]);
    }
    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 'std::pair<long long int, long long int> dfs2(long long int, long long int)':
count_triplets.cpp:48: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]
   48 | for(int i=0;i<tr[nw].size();i++){
      |             ~^~~~~~~~~~~~~~
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:99: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]
   99 |     for(int i=0;i<rt.size();i++){
      |                 ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 28500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 28500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1061 ms 47200 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 28480 KB Output is correct
2 Correct 17 ms 28488 KB Output is correct
3 Correct 21 ms 28572 KB Output is correct
4 Correct 16 ms 28628 KB Output is correct
5 Correct 20 ms 28648 KB Output is correct
6 Correct 18 ms 28588 KB Output is correct
7 Correct 22 ms 28628 KB Output is correct
8 Correct 17 ms 28628 KB Output is correct
9 Correct 16 ms 28500 KB Output is correct
10 Correct 18 ms 28492 KB Output is correct
11 Correct 16 ms 28500 KB Output is correct
12 Correct 15 ms 28604 KB Output is correct
13 Correct 16 ms 28596 KB Output is correct
14 Correct 15 ms 28580 KB Output is correct
15 Correct 19 ms 28504 KB Output is correct
16 Correct 15 ms 28500 KB Output is correct
17 Correct 15 ms 28500 KB Output is correct
18 Correct 15 ms 28500 KB Output is correct
19 Correct 19 ms 28500 KB Output is correct
20 Correct 19 ms 28600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 37192 KB Output is correct
2 Correct 120 ms 37156 KB Output is correct
3 Correct 119 ms 37144 KB Output is correct
4 Correct 118 ms 37204 KB Output is correct
5 Correct 115 ms 37196 KB Output is correct
6 Correct 142 ms 42980 KB Output is correct
7 Correct 141 ms 40808 KB Output is correct
8 Correct 152 ms 39912 KB Output is correct
9 Correct 132 ms 39044 KB Output is correct
10 Correct 121 ms 37188 KB Output is correct
11 Correct 128 ms 37116 KB Output is correct
12 Correct 118 ms 37168 KB Output is correct
13 Correct 123 ms 37240 KB Output is correct
14 Correct 153 ms 36956 KB Output is correct
15 Correct 101 ms 36804 KB Output is correct
16 Correct 74 ms 35784 KB Output is correct
17 Correct 96 ms 37012 KB Output is correct
18 Correct 92 ms 36560 KB Output is correct
19 Correct 93 ms 36964 KB Output is correct
20 Correct 93 ms 36612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 28536 KB Output is correct
2 Correct 20 ms 28500 KB Output is correct
3 Correct 19 ms 28588 KB Output is correct
4 Incorrect 16 ms 28624 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 129 ms 37272 KB Output is correct
2 Correct 145 ms 37316 KB Output is correct
3 Correct 149 ms 38728 KB Output is correct
4 Incorrect 164 ms 40660 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 28500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 28500 KB Output isn't correct
2 Halted 0 ms 0 KB -