Submission #2544989
Source Code Expand
#include <iostream> #include <vector> using namespace std; int N, M, A[100009], B[100009], col[100009], z[2]; vector<int>x[100009]; bool OK = false; void dfs(int pos, int depth) { if (col[pos] >= 0) { if (col[pos] != depth) OK = true; return; } col[pos] = depth; z[depth]++; for (int i = 0; i < x[pos].size(); i++) dfs(x[pos][i], depth ^ 1); } int main() { cin >> N >> M; for (int i = 1; i <= M; i++) { cin >> A[i] >> B[i]; x[A[i]].push_back(B[i]); x[B[i]].push_back(A[i]); } for (int i = 1; i <= N; i++) col[i] = -1; dfs(1, 0); long long G1 = 1LL * z[0] * z[1]; if (OK == true) G1 = 1LL * N*(N - 1) / 2LL; cout << G1 - M << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - 3 Steps |
User | E869120 |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 696 Byte |
Status | AC |
Exec Time | 95 ms |
Memory | 7680 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 | 2 ms | 2560 KB |
01-02.txt | AC | 2 ms | 2560 KB |
01-03.txt | AC | 2 ms | 2560 KB |
01-04.txt | AC | 2 ms | 2560 KB |
01-05.txt | AC | 2 ms | 2560 KB |
01-06.txt | AC | 3 ms | 2688 KB |
01-07.txt | AC | 2 ms | 2560 KB |
01-08.txt | AC | 2 ms | 2560 KB |
01-09.txt | AC | 3 ms | 2688 KB |
01-10.txt | AC | 4 ms | 2688 KB |
02-01.txt | AC | 93 ms | 7680 KB |
02-02.txt | AC | 94 ms | 6912 KB |
02-03.txt | AC | 92 ms | 6912 KB |
02-04.txt | AC | 93 ms | 6912 KB |
02-05.txt | AC | 94 ms | 6912 KB |
02-06.txt | AC | 92 ms | 6912 KB |
02-07.txt | AC | 91 ms | 7168 KB |
02-08.txt | AC | 93 ms | 7680 KB |
02-09.txt | AC | 95 ms | 7296 KB |
02-10.txt | AC | 55 ms | 4864 KB |
02-11.txt | AC | 71 ms | 5120 KB |
02-12.txt | AC | 90 ms | 6400 KB |
02-13.txt | AC | 86 ms | 6784 KB |
02-14.txt | AC | 92 ms | 7296 KB |
sample-01.txt | AC | 2 ms | 2560 KB |
sample-02.txt | AC | 2 ms | 2560 KB |