Submission #120704

# Submission time Handle Problem Language Result Execution time Memory
120704 2019-06-25T09:21:04 Z _demon_ Duathlon (APIO18_duathlon) C++14
0 / 100
1000 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m;
ll child[100009];
ll ans;
vector<ll>v[100009];
void dfs1(int node,int p){
    child[node]=1;
    for(int i=0;i<v[node].size();i++){
        int u=v[node][i];
        if(u==p)continue;
        dfs1(u,node);
        child[node]+=child[u];
    }
}
void dfs2(int node,int p){
    ll sum=0;
    for(int i=0;i<v[node].size();i++){
        int u=v[node][i];
        if(u==p)continue;
        sum+=(child[u]*(n-child[u]-1))*2;
    }
    ans+=sum;
    for(int i=0;i<v[node].size();i++){
        int u=v[node][i];
        if(u==p)continue;
        dfs2(u,node);
    }
}
int main(){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs1(0,0);
    dfs2(0,0);
    cout<<ans<<endl;
}

Compilation message

count_triplets.cpp: In function 'void dfs1(int, int)':
count_triplets.cpp:10:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v[node].size();i++){
                 ~^~~~~~~~~~~~~~~
count_triplets.cpp: In function 'void dfs2(int, int)':
count_triplets.cpp:19:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v[node].size();i++){
                 ~^~~~~~~~~~~~~~~
count_triplets.cpp:25:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v[node].size();i++){
                 ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 946 ms 1048576 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 946 ms 1048576 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 238280 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 133 ms 8500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 127 ms 8548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 946 ms 1048576 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 946 ms 1048576 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -