Submission #701512

# Submission time Handle Problem Language Result Execution time Memory
701512 2023-02-21T11:40:35 Z Abrar_Al_Samit Duathlon (APIO18_duathlon) C++17
0 / 100
446 ms 1048576 KB
#include<bits/stdc++.h>
using namespace std;

const int nax = 1002;

vector<int>g[nax];
int n, m;
long long ans = 0;
bool vis[nax];
int sub[nax];

int dfs1(int v, int p) {
  sub[v] = 1;
  vis[v] = 1;
  for(int u : g[v]) if(u!=p) {
    sub[v] += dfs1(u, v);
  }
  return sub[v];
}
void dfs2(int v,int p, int anc) {
  for(int i=0; i<g[v].size(); ++i) if(g[v][i]!=p) {
    dfs2(g[v][i], v, anc+1);
    for(int j=i+1; j<g[v].size(); ++j) if(g[v][j]!=p) {
      ans += sub[g[v][i]] * 1LL * sub[g[v][j]];
    }
  }
  ans += (sub[v]-1) * 1LL * anc;
}
void PlayGround() {
  cin>>n>>m;
  for(int i=0; i<m; ++i) {
    int u, v;
    cin>>u>>v;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  for(int i=1; i<=n; ++i) if(!vis[i]) {
    dfs1(i, i);
    dfs2(i, i, 0);
  }
  cout<<ans*2<<'\n';

  // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  PlayGround();
  return 0;
}

Compilation message

count_triplets.cpp: In function 'void dfs2(int, int, int)':
count_triplets.cpp:21:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |   for(int i=0; i<g[v].size(); ++i) if(g[v][i]!=p) {
      |                ~^~~~~~~~~~~~
count_triplets.cpp:23:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int j=i+1; j<g[v].size(); ++j) if(g[v][j]!=p) {
      |                    ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 446 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 446 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 446 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 446 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -