Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdlib>
- #include <cmath>
- #include <cstring>
- #include <cstdarg>
- #include <cassert>
- #include <algorithm>
- #include <vector>
- #include <string>
- using namespace std;
- #define eprintf(...) fprintf(stderr, __VA_ARGS__)
- #define pb push_back
- #define mp make_pair
- #define TASKNAME ""
- #define sz(x) ((int)(x).size())
- typedef long long ll;
- typedef vector<ll> vll;
- typedef vector<int> vi;
- typedef vector<vi> vvi;
- typedef vector<bool> vb;
- typedef pair<int, int> pii;
- #ifdef _WIN32
- #define LLD "%I64d"
- #elif linux
- #define LLD "%lld"
- #else
- #error Invalid OS...
- #endif
- const int MAXN = 5000;
- int n;
- char g[MAXN][MAXN];
- int ty[MAXN];
- ll tcnt[4];
- ll tg[2][4][4];
- int main() {
- #ifdef DEBUG
- freopen("std.in", "r", stdin);
- freopen("std.out", "w", stdout);
- #endif
- int n, m;
- while (scanf("%d%d", &n, &m) >= 1) {
- memset(g, 1, sizeof g);
- vi as(m), bs(m);
- for (int i = 0; i < m; i++) {
- scanf("%d%d", &as[i], &bs[i]), as[i]--, bs[i]--;
- if (as[i] > bs[i]) swap(as[i], bs[i]);
- g[as[i]][bs[i]] = g[bs[i]][as[i]] = false;
- }
- ll ans = n;
- ans += ll(n) * (n - 1) / 2 - m;
- if (n >= 3) {
- ll c3 = ll(n) * (n - 1) * (n - 2) / 6;
- for (int i = 0; i < m; i++) {
- int a = as[i], b = bs[i];
- for (int c = 0; c < n; c++) if (a != c && b != c) {
- if (!g[a][c] && !g[b][c]) {
- if (b >= c) continue;
- } else if (!g[a][c]) {
- if (b >= c) continue;
- } else if (!g[b][c]) {
- if (a >= c) continue;
- }
- c3--;
- }
- }
- ans += c3;
- }
- if (n >= 4) {
- ll cnts[7];
- memset(cnts, 0, sizeof cnts);
- for (int ed = 0; ed < m; ed++) {
- int a = as[ed], b = bs[ed];
- memset(ty, -1, sizeof ty);
- memset(tcnt, 0, sizeof tcnt);
- for (int i = 0; i < n; i++) if (i != a && i != b) {
- ty[i] = !g[a][i] + !g[b][i];
- tcnt[ty[i]]++;
- }
- memset(tg, 0, sizeof tg);
- for (int e2 = 0; e2 < m; e2++) {
- int t1 = ty[as[e2]], t2 = ty[bs[e2]];
- if (t1 > t2) swap(t1, t2);
- if (t1 >= 0 && t2 >= 0) {
- tg[1][t1][t2]++;
- }
- }
- for (int a = 0; a < 4; a++) {
- ll ccnt = tcnt[a] * (tcnt[a] - 1) / 2;
- tg[0][a][a] = ccnt - tg[1][a][a];
- for (int b = a + 1; b < 4; b++) {
- ll ccnt = tcnt[a] * tcnt[b];
- tg[0][a][b] = ccnt - tg[1][a][b];
- }
- }
- for (int conn = 0; conn < 2; conn++)
- for (int t1 = 0; t1 < 3; t1++)
- for (int t2 = t1; t2 < 3; t2++) {
- int ccnt = 1 + t1 + t2 + conn;
- assert(1 <= ccnt && ccnt <= 6);
- cnts[ccnt] += tg[conn][t1][t2];
- }
- }
- for (int i = 1; i <= 6; i++) {
- assert(cnts[i] % i == 0);
- cnts[i] /= i;
- }
- ll c4 = ll(n) * (n - 1) * (n - 2) * (n - 3) / 24;
- for (int i = 1; i <= 6; i++)
- c4 -= cnts[i];
- assert(c4 >= 0);
- ans += c4;
- }
- printf(LLD"\n", ans);
- #ifndef DEBUG
- break;
- #endif
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement