Submission #747693

# Submission time Handle Problem Language Result Execution time Memory
747693 2023-05-24T13:33:27 Z 1075508020060209tc Duathlon (APIO18_duathlon) C++14
0 / 100
1000 ms 1048576 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long

int n;int m;
vector<int>e[300005];

int sz[300005];
int ans;
void dfssz(int nw,int pa){
sz[nw]=1;
for(int i=0;i<e[nw].size();i++){
    int v=e[nw][i];
    if(v==pa){continue;}
    dfssz(v,nw);
    sz[nw]+=sz[v];
}
}



void dfs(int nw,int pa,int rtsz){
ans+=(rtsz-sz[nw])*(sz[nw]-1);
for(int i=0;i<e[nw].size();i++){
    int v=e[nw][i];
    if(v==pa){continue;}
    dfs(v,nw,rtsz);
    ans+=sz[v]*(rtsz-1-sz[v]);
}
}


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(sz[i]==0){
            dfssz(i,0);
            rt.push_back(i);
        }
    }
    for(int i=0;i<1;i++){
        dfs(rt[i],0,sz[rt[i]]);
    }
    cout<<ans<<endl;
}

Compilation message

count_triplets.cpp: In function 'void dfssz(long long int, long long int)':
count_triplets.cpp:13: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]
   13 | for(int i=0;i<e[nw].size();i++){
      |             ~^~~~~~~~~~~~~
count_triplets.cpp: In function 'void dfs(long long int, long long int, long long int)':
count_triplets.cpp:25: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]
   25 | for(int i=0;i<e[nw].size();i++){
      |             ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 469 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 469 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1074 ms 505272 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 5 ms 7380 KB Output is correct
3 Correct 4 ms 7368 KB Output is correct
4 Correct 5 ms 7380 KB Output is correct
5 Correct 6 ms 7380 KB Output is correct
6 Correct 5 ms 7384 KB Output is correct
7 Correct 4 ms 7356 KB Output is correct
8 Correct 7 ms 7380 KB Output is correct
9 Correct 7 ms 7380 KB Output is correct
10 Incorrect 5 ms 7380 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 111 ms 12192 KB Output is correct
2 Correct 104 ms 12160 KB Output is correct
3 Correct 113 ms 12232 KB Output is correct
4 Correct 114 ms 12240 KB Output is correct
5 Correct 116 ms 12220 KB Output is correct
6 Correct 140 ms 15888 KB Output is correct
7 Correct 156 ms 14900 KB Output is correct
8 Correct 129 ms 14184 KB Output is correct
9 Correct 123 ms 13540 KB Output is correct
10 Incorrect 113 ms 12144 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7380 KB Output is correct
2 Correct 5 ms 7380 KB Output is correct
3 Runtime error 593 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 87 ms 12236 KB Output is correct
2 Correct 122 ms 12212 KB Output is correct
3 Runtime error 812 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 469 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 469 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -