Submission #3015916
Source Code Expand
#include <iostream> #include <vector> using namespace std; typedef long long ll; ll n, m, a, b, color[100100]; vector<ll> G[100100]; bool nibu = true; bool dfs(ll x, ll c){ color[x] = c; for (ll i = 0; i < G[x].size(); i++){ if (color[G[x][i]] == c) return false; if (color[G[x][i]] == 0 && !dfs(G[x][i], -c)) return false; } return true; } int main(void){ // Your code here! cin >> n >> m; for (ll i = 0; i < m; i++){ cin >> a >> b; G[a].push_back(b); G[b].push_back(a); } if (dfs(1, 1)){ ll katahou = 0; for (ll i = 1; i <= n; i++){ if (color[i] == 1) katahou++; } cout << katahou * (n - katahou) - m << endl; } else { cout << n * (n - 1) / 2 - m << endl; } }
Submission Info
Submission Time | |
---|---|
Task | C - 3 Steps |
User | kwfumou1242 |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 835 Byte |
Status | AC |
Exec Time | 81 ms |
Memory | 7424 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 | 2688 KB |
01-07.txt | AC | 3 ms | 2560 KB |
01-08.txt | AC | 3 ms | 2560 KB |
01-09.txt | AC | 3 ms | 2688 KB |
01-10.txt | AC | 4 ms | 2688 KB |
02-01.txt | AC | 74 ms | 6912 KB |
02-02.txt | AC | 77 ms | 7040 KB |
02-03.txt | AC | 78 ms | 7040 KB |
02-04.txt | AC | 81 ms | 7040 KB |
02-05.txt | AC | 80 ms | 7040 KB |
02-06.txt | AC | 79 ms | 7040 KB |
02-07.txt | AC | 71 ms | 6144 KB |
02-08.txt | AC | 74 ms | 6912 KB |
02-09.txt | AC | 75 ms | 7040 KB |
02-10.txt | AC | 46 ms | 5376 KB |
02-11.txt | AC | 59 ms | 5632 KB |
02-12.txt | AC | 73 ms | 6784 KB |
02-13.txt | AC | 74 ms | 6912 KB |
02-14.txt | AC | 80 ms | 7424 KB |
sample-01.txt | AC | 3 ms | 2560 KB |
sample-02.txt | AC | 3 ms | 2560 KB |