Submission #1671872
Source Code Expand
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
#define MP make_pair
#define PB push_back
#define FF first
#define SS second
#define FORN(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }
#define MOD 1000000007
#define INF 2000000000
int GLL(LL& x) {
return scanf("%lld", &x);
}
int GI(int& x) {
return scanf("%d", &x);
}
int n, m;
vector<vector<int>> adj;
const int MAXN = 100005;
int color[MAXN];
bool bipartite;
void dfs(int u, int c) {
color[u] = c;
for (auto v : adj[u]) {
if (color[v] == -1) {
dfs(v, 1-c);
}
else if (color[v] == color[u]) {
bipartite = false;
}
}
}
int main() {
GI(n);
GI(m);
adj.resize(n+1);
FORN(i, m) {
int a, b;
GI(a);
GI(b);
adj[a].PB(b);
adj[b].PB(a);
}
memset(color, -1, sizeof color);
bipartite = true;
dfs(1, 0);
if (!bipartite) {
printf("%lld\n", 1LL*n*(n-1)/2 - m);
}
else {
int cnt0 = 0;
int cnt1 = 0;
FOR1(i, n) {
if (color[i] == 0) cnt0++;
else cnt1++;
}
printf("%lld\n", 1LL*cnt0*cnt1 - m);
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - 3 Steps |
| User | chenmark |
| Language | C++14 (GCC 5.4.1) |
| Score | 500 |
| Code Size | 1836 Byte |
| Status | AC |
| Exec Time | 43 ms |
| Memory | 6784 KiB |
Judge Result
| Set Name | sample | all | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| 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 | 1 ms | 640 KiB |
| 01-02.txt | AC | 1 ms | 640 KiB |
| 01-03.txt | AC | 1 ms | 640 KiB |
| 01-04.txt | AC | 1 ms | 640 KiB |
| 01-05.txt | AC | 2 ms | 640 KiB |
| 01-06.txt | AC | 2 ms | 640 KiB |
| 01-07.txt | AC | 1 ms | 640 KiB |
| 01-08.txt | AC | 2 ms | 640 KiB |
| 01-09.txt | AC | 2 ms | 640 KiB |
| 01-10.txt | AC | 2 ms | 768 KiB |
| 02-01.txt | AC | 43 ms | 6656 KiB |
| 02-02.txt | AC | 39 ms | 6144 KiB |
| 02-03.txt | AC | 42 ms | 6144 KiB |
| 02-04.txt | AC | 43 ms | 6144 KiB |
| 02-05.txt | AC | 40 ms | 6144 KiB |
| 02-06.txt | AC | 42 ms | 6144 KiB |
| 02-07.txt | AC | 39 ms | 5376 KiB |
| 02-08.txt | AC | 42 ms | 6784 KiB |
| 02-09.txt | AC | 41 ms | 6400 KiB |
| 02-10.txt | AC | 20 ms | 2048 KiB |
| 02-11.txt | AC | 27 ms | 2560 KiB |
| 02-12.txt | AC | 41 ms | 4608 KiB |
| 02-13.txt | AC | 35 ms | 5632 KiB |
| 02-14.txt | AC | 42 ms | 6528 KiB |
| sample-01.txt | AC | 1 ms | 640 KiB |
| sample-02.txt | AC | 1 ms | 640 KiB |