Submission #4062851


Source Code Expand

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m, a, b, c[112345];
    V g[112345];

    memset(c, -1, sizeof(c));

    cin >> n >> m;
    REP(i, m)
    {
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    c[1] = 0;

    int w = 1;

    queue<int> q;
    q.push(1);

    while (q.size())
    {
        int i = q.front();
        q.pop();

        for (int j : g[i])
        {
            if (c[j] == c[i])
            {
                cout << ((ll)n * (n - 1) / 2 - m) << endl;
                return 0;
            }

            if (c[j] == -1)
            {
                c[j] = 1 - c[i];
                q.push(j);

                w += c[j] == 0;
            }
        }
    }

    cout << ((ll)w * (n - w) - m) << endl;

    return 0;
}

Submission Info

Submission Time
Task C - 3 Steps
User Kats
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1681 Byte
Status AC
Exec Time 40 ms
Memory 6656 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 28
Set Name Test Cases
sample sample-01.txt, sample-02.txt
all sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, sample-01.txt, sample-02.txt
Case Name Status Exec Time Memory
01-01.txt AC 3 ms 3328 KB
01-02.txt AC 3 ms 3328 KB
01-03.txt AC 3 ms 3328 KB
01-04.txt AC 3 ms 3328 KB
01-05.txt AC 2 ms 3328 KB
01-06.txt AC 2 ms 3328 KB
01-07.txt AC 3 ms 3328 KB
01-08.txt AC 3 ms 3328 KB
01-09.txt AC 3 ms 3328 KB
01-10.txt AC 3 ms 3456 KB
02-01.txt AC 34 ms 6272 KB
02-02.txt AC 38 ms 6528 KB
02-03.txt AC 38 ms 6528 KB
02-04.txt AC 40 ms 6528 KB
02-05.txt AC 40 ms 6528 KB
02-06.txt AC 37 ms 6528 KB
02-07.txt AC 32 ms 5504 KB
02-08.txt AC 34 ms 6272 KB
02-09.txt AC 34 ms 6528 KB
02-10.txt AC 18 ms 4736 KB
02-11.txt AC 26 ms 4864 KB
02-12.txt AC 35 ms 5504 KB
02-13.txt AC 33 ms 6656 KB
02-14.txt AC 38 ms 6528 KB
sample-01.txt AC 3 ms 3328 KB
sample-02.txt AC 3 ms 3328 KB