Submission #1691602
Source Code Expand
#include <iostream> #include <vector> using namespace std; typedef long long ll; ll n, m, color[100000], ans; vector<int>g[100000]; bool vipartiteGraph(int node, int c) { color[node] = c; bool res = true; for (int i = 0; i < g[node].size(); i++) { if (color[g[node][i]] == INT32_MAX) { res = res && vipartiteGraph(g[node][i], (c+1)%2); } else if (color[g[node][i]] == c) { res = false; } } return res; } int main() { cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; g[a - 1].push_back(b - 1); g[b - 1].push_back(a - 1); } for (int i = 0; i < n; i++)color[i] = INT32_MAX; if (vipartiteGraph(0, 0)) {//二部グラフであったら //cout << "二部グラフである" << endl; ll brack = 0, white = 0; for (int i = 0; i < n; i++) { if (color[i] == 0)brack++; else white++; } ans = brack*white-m; //cout << "brack:" << brack << " white:" << white << endl; } else {//二部グラフでなかったら //cout << "二部グラフでない" << endl; ans = n*(n - 1) / 2 - m; } cout << ans << endl; }
Submission Info
Submission Time | |
---|---|
Task | C - 3 Steps |
User | ZxFkcjgN |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 1132 Byte |
Status | AC |
Exec Time | 104 ms |
Memory | 6912 KB |
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 | 3 ms | 2560 KB |
01-02.txt | AC | 3 ms | 2560 KB |
01-03.txt | AC | 3 ms | 2560 KB |
01-04.txt | AC | 3 ms | 2560 KB |
01-05.txt | AC | 3 ms | 2560 KB |
01-06.txt | AC | 3 ms | 2560 KB |
01-07.txt | AC | 3 ms | 2560 KB |
01-08.txt | AC | 3 ms | 2560 KB |
01-09.txt | AC | 4 ms | 2688 KB |
01-10.txt | AC | 5 ms | 2688 KB |
02-01.txt | AC | 87 ms | 6144 KB |
02-02.txt | AC | 104 ms | 6528 KB |
02-03.txt | AC | 94 ms | 6528 KB |
02-04.txt | AC | 99 ms | 6528 KB |
02-05.txt | AC | 93 ms | 6528 KB |
02-06.txt | AC | 91 ms | 6528 KB |
02-07.txt | AC | 88 ms | 5120 KB |
02-08.txt | AC | 90 ms | 6272 KB |
02-09.txt | AC | 89 ms | 6528 KB |
02-10.txt | AC | 56 ms | 3968 KB |
02-11.txt | AC | 70 ms | 4352 KB |
02-12.txt | AC | 89 ms | 5760 KB |
02-13.txt | AC | 93 ms | 6400 KB |
02-14.txt | AC | 94 ms | 6912 KB |
sample-01.txt | AC | 3 ms | 2560 KB |
sample-02.txt | AC | 3 ms | 2560 KB |