Submission #1671264
Source Code Expand
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } //--------------------------------------------------------------------------------------------------- /*--------------------------------------------------------------------------------------------------- ∧_∧ ∧_∧ (´<_` ) Welcome to My Coding Space! ( ´_ゝ`) / ⌒i / \ | | / / ̄ ̄ ̄ ̄/ | __(__ニつ/ _/ .| .|____ \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ typedef long long ll; int N, M; vector<int> E[101010]; //--------------------------------------------------------------------------------------------------- int col[101010]; int ok = 1; void dfs(int cu) { fore(to, E[cu]) { if (col[cu] == col[to]) { ok = 0; return; } if (!col[to]) { col[to] = 3 - col[cu]; dfs(to); } } } //--------------------------------------------------------------------------------------------------- void _main() { cin >> N >> M; rep(i, 0, M) { int a, b; cin >> a >> b; a--; b--; E[a].push_back(b); E[b].push_back(a); } col[0] = 1; dfs(0); if (ok) { int B = 0, W = 0; rep(i, 0, N) { if (col[i] == 1) B++; else W++; } ll ans = 1LL * B * W - M; cout << ans << endl; } else { ll ans = 1LL * N * (N - 1) / 2 - M; cout << ans << endl; } }
Submission Info
Submission Time | |
---|---|
Task | C - 3 Steps |
User | hamayanhamayan |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 1982 Byte |
Status | AC |
Exec Time | 42 ms |
Memory | 6400 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 | 2688 KB |
01-02.txt | AC | 3 ms | 2688 KB |
01-03.txt | AC | 3 ms | 2688 KB |
01-04.txt | AC | 3 ms | 2688 KB |
01-05.txt | AC | 3 ms | 2688 KB |
01-06.txt | AC | 3 ms | 2688 KB |
01-07.txt | AC | 3 ms | 2688 KB |
01-08.txt | AC | 3 ms | 2688 KB |
01-09.txt | AC | 3 ms | 2688 KB |
01-10.txt | AC | 3 ms | 2688 KB |
02-01.txt | AC | 39 ms | 6400 KB |
02-02.txt | AC | 39 ms | 6144 KB |
02-03.txt | AC | 39 ms | 6144 KB |
02-04.txt | AC | 39 ms | 6144 KB |
02-05.txt | AC | 39 ms | 6144 KB |
02-06.txt | AC | 40 ms | 6144 KB |
02-07.txt | AC | 35 ms | 5632 KB |
02-08.txt | AC | 39 ms | 6400 KB |
02-09.txt | AC | 42 ms | 6400 KB |
02-10.txt | AC | 18 ms | 4096 KB |
02-11.txt | AC | 26 ms | 4224 KB |
02-12.txt | AC | 35 ms | 5248 KB |
02-13.txt | AC | 32 ms | 6016 KB |
02-14.txt | AC | 38 ms | 6400 KB |
sample-01.txt | AC | 3 ms | 2688 KB |
sample-02.txt | AC | 3 ms | 2688 KB |