Submission #701518

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

const int nax = 1e5 + 2;

vector<int>g[nax];
int n, m;
bool vis[nax];
int cr, sm;

void dfs(int v) {
  vis[v] = true;
  sm += g[v].size();
  ++cr;
  for(int u : g[v]) if(!vis[u]) {
    dfs(u);
  }
}
long long C(int n, int r) {
  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;
}
long long P(int n, int r) {
  long long ret = 1;
  for(int i=n-r+1; i<=n; ++i) {
    ret *= i;
  }
  return ret;
}
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);
  }
  long long ans = 0;
  for(int i=1; i<=n; ++i) if(!vis[i]) {
    cr = sm = 0;
    dfs(i);

    if(sm==cr * 2) {
      if(cr>=3) ans += C(cr, 3);
    } else {
      long long cur = 0;
      for(int i=1; i<=cr-2; ++i) {
        cur += P(cr-i, 2);
      }
      cur *= 2;
      ans += cur;
    }
  }
  cout<<ans<<'\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 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 10140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 7128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 7132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -