Submission #701506

# Submission time Handle Problem Language Result Execution time Memory
701506 2023-02-21T11:32:00 Z Abrar_Al_Samit Duathlon (APIO18_duathlon) C++17
0 / 100
489 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 u : g[v]) if(u!=p) {
    long long one = sub[u];
    long long two = sub[v] - sub[u] - 1;
    ans += one * two;
    dfs2(u, v, anc+1);

    one = sub[v] - 1;
    ans += one * 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;
}
# Verdict Execution time Memory Grader output
1 Runtime error 489 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 489 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 356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 528 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 596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 489 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 489 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -