Submission #120722

# Submission time Handle Problem Language Result Execution time Memory
120722 2019-06-25T10:22:28 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;
ll w[100009];
vector<ll>v[100009];
int done[100009];
void dfs1(int node,int p){
    child[node]=1;
  	done[node]=1;
    if(node!=p)w[node]=w[p]+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];
    }
}
int a[100009];
void dfs2(int node,int p){
    ll sum=0;
    for(int i=0;i<v[node].size();i++){
        int u=v[node][i];
        if(w[u]>w[node]){
            sum+=child[u]*(n-child[u]-1);
        }
        else{
            sum+=(n-child[node])*(child[node]-1);
        }
    }
    a[node]=sum;
    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);
  	for(int i=0;i<n;i++){
      if(done[i]==0){
        while(1){
          
        }
      }
    }
//  for(int i=0;i<n;i++)cout<<w[i]<<" ";
//  cout<<endl;
    dfs2(0,0);
//  for(int i=0;i<n;i++)cout<<a[i]<<" ";
//  cout<<endl;
    cout<<ans<<endl;
}

Compilation message

count_triplets.cpp: In function 'void dfs1(int, int)':
count_triplets.cpp:14: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:24:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v[node].size();i++){
                 ~^~~~~~~~~~~~~~~
count_triplets.cpp:35: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 796 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 796 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 1078 ms 238020 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 5 ms 2688 KB Output is correct
3 Correct 4 ms 2688 KB Output is correct
4 Correct 4 ms 2816 KB Output is correct
5 Correct 5 ms 2816 KB Output is correct
6 Correct 4 ms 2816 KB Output is correct
7 Correct 5 ms 2816 KB Output is correct
8 Correct 4 ms 2816 KB Output is correct
9 Correct 5 ms 2688 KB Output is correct
10 Execution timed out 1057 ms 2688 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 131 ms 8696 KB Output is correct
2 Correct 142 ms 8696 KB Output is correct
3 Correct 136 ms 8824 KB Output is correct
4 Correct 135 ms 8800 KB Output is correct
5 Correct 128 ms 8756 KB Output is correct
6 Correct 138 ms 11484 KB Output is correct
7 Correct 134 ms 11000 KB Output is correct
8 Correct 145 ms 10396 KB Output is correct
9 Correct 142 ms 9848 KB Output is correct
10 Execution timed out 1055 ms 8368 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 2688 KB Output is correct
2 Correct 5 ms 2816 KB Output is correct
3 Runtime error 903 ms 1048576 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 135 ms 8740 KB Output is correct
2 Correct 134 ms 8668 KB Output is correct
3 Execution timed out 1148 ms 1012176 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 796 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 796 ms 1048576 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -