Submission #701522

# Submission time Handle Problem Language Result Execution time Memory
701522 2023-02-21T12:06:00 Z Abrar_Al_Samit Duathlon (APIO18_duathlon) C++17
23 / 100
1000 ms 1048576 KB
#include<bits/stdc++.h>
using namespace std;
 
const int nax = 1e5 + 2;
 
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];
}
long long C(int n, int r) {
  if(n<r) return 0;

  long long ret = 1;
  for(int i=n-r+1; i<=n; ++i) {
    ret *= i;
  }
  for(int i=1; i<=r; ++i) {
    ret /= i;
  }
  return ret;
}
void dfs2(int v,int p, int r) {

  long long cur = C(sub[v]-1, 2);
  for(int u : g[v]) if(u!=p) {
    dfs2(u, v, r);

    cur -= C(sub[u], 2);
  }
  ans += cur;
  ans += (sub[v]-1) * 1LL * (sub[r] - sub[v]);
}
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, i);
  }
  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 435 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 435 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 536576 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2684 KB Output is correct
3 Correct 2 ms 2680 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2684 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 3 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 6352 KB Output is correct
2 Correct 40 ms 7640 KB Output is correct
3 Correct 43 ms 7544 KB Output is correct
4 Correct 42 ms 7628 KB Output is correct
5 Correct 45 ms 7632 KB Output is correct
6 Correct 59 ms 11728 KB Output is correct
7 Correct 58 ms 10260 KB Output is correct
8 Correct 48 ms 9584 KB Output is correct
9 Correct 46 ms 8912 KB Output is correct
10 Correct 40 ms 7636 KB Output is correct
11 Correct 49 ms 7552 KB Output is correct
12 Correct 40 ms 7612 KB Output is correct
13 Correct 48 ms 7544 KB Output is correct
14 Correct 34 ms 7352 KB Output is correct
15 Correct 32 ms 7052 KB Output is correct
16 Correct 23 ms 6096 KB Output is correct
17 Correct 28 ms 7844 KB Output is correct
18 Correct 28 ms 7856 KB Output is correct
19 Correct 34 ms 7916 KB Output is correct
20 Correct 28 ms 7884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2684 KB Output is correct
3 Runtime error 554 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 6380 KB Output is correct
2 Correct 45 ms 7588 KB Output is correct
3 Runtime error 671 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 435 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 435 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -