Submission #4065393
Source Code Expand
#include <bits/stdc++.h> #define rep(i,m,n) for(int i = (m); i < (n); i++) #define rrep(i,m,n) for(int i = (m); i >= (n); i--) #define print(x) cout << (x) << endl; #define print2(x,y) cout << (x) << " " << (y) << endl; #define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];} #define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl; #define INF (1e18) using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; typedef pair<ll, ll> lpair; ll N,M; ll A[100010], B[100010]; vector<ll> tree[100010]; ll d[100010]; ll check[100010] = {}; bool is_two = true; void dfs(ll cur, ll val){ if(!check[cur]){ check[cur] = 1; d[cur] = val; }else{ if(d[cur] != val){ is_two = false; } return; } for(auto &e: tree[cur]){ if(val == 0){ dfs(e, 1); }else{ dfs(e, 0); } } } int main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> N >> M; rep(i,0,M){ cin >> A[i] >> B[i]; A[i]--; B[i]--; tree[A[i]].push_back(B[i]); tree[B[i]].push_back(A[i]); } memset(d, -1, sizeof(d)); dfs(0, 0); if(!is_two){ print(N * (N-1) / 2 - M); }else{ ll cnt = 0; rep(i,0,N){ if(d[i] == 1) cnt++; } print(cnt * (N - cnt) - M); } }
Submission Info
Submission Time | |
---|---|
Task | C - 3 Steps |
User | yuji9511 |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 1503 Byte |
Status | AC |
Exec Time | 40 ms |
Memory | 9984 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 | 3584 KB |
01-02.txt | AC | 3 ms | 3584 KB |
01-03.txt | AC | 2 ms | 3584 KB |
01-04.txt | AC | 3 ms | 3584 KB |
01-05.txt | AC | 3 ms | 3584 KB |
01-06.txt | AC | 3 ms | 3584 KB |
01-07.txt | AC | 3 ms | 3584 KB |
01-08.txt | AC | 3 ms | 3584 KB |
01-09.txt | AC | 3 ms | 3712 KB |
01-10.txt | AC | 3 ms | 3712 KB |
02-01.txt | AC | 40 ms | 9856 KB |
02-02.txt | AC | 39 ms | 9344 KB |
02-03.txt | AC | 39 ms | 9344 KB |
02-04.txt | AC | 39 ms | 9344 KB |
02-05.txt | AC | 39 ms | 9344 KB |
02-06.txt | AC | 39 ms | 9344 KB |
02-07.txt | AC | 38 ms | 9472 KB |
02-08.txt | AC | 40 ms | 9984 KB |
02-09.txt | AC | 40 ms | 9600 KB |
02-10.txt | AC | 20 ms | 7808 KB |
02-11.txt | AC | 28 ms | 7936 KB |
02-12.txt | AC | 36 ms | 8832 KB |
02-13.txt | AC | 35 ms | 9344 KB |
02-14.txt | AC | 39 ms | 9728 KB |
sample-01.txt | AC | 3 ms | 3584 KB |
sample-02.txt | AC | 2 ms | 3584 KB |