Submission #1833882
Source Code Expand
#include <algorithm> #include <climits> #include <cstdio> #include <cstdlib> #include <iostream> #include <vector> #define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i)) using namespace std; typedef long long ll; typedef vector<int> vertex; typedef vector<vertex> graph; ll n, m; graph g; void add_edge(int a, int b){ g[a].push_back(b); g[b].push_back(a); } int used[100000]; ll cnt(ll u, ll d, bool &tr){ if(used[u]){ if(used[u]!=2-d) tr = true; return 0; } used[u] = 2-d; ll res = 0; if(d==0) res++; for(int v: g[u]){ res += cnt(v, !d, tr); } return res; } int main(){ cin>>n>>m; g = graph(n); rep(i, m){ int a, b; cin>>a>>b; a--; b--; add_edge(a, b); } bool tr = false; ll t = cnt(0, 0, tr); if(tr) cout<<n*(n-1)/2-m<<endl; else cout<<t*(n-t)-m<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - 3 Steps |
User | Lepton |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 854 Byte |
Status | AC |
Exec Time | 97 ms |
Memory | 6656 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 | 1 ms | 256 KB |
01-02.txt | AC | 1 ms | 256 KB |
01-03.txt | AC | 1 ms | 256 KB |
01-04.txt | AC | 1 ms | 256 KB |
01-05.txt | AC | 1 ms | 256 KB |
01-06.txt | AC | 2 ms | 256 KB |
01-07.txt | AC | 1 ms | 256 KB |
01-08.txt | AC | 2 ms | 256 KB |
01-09.txt | AC | 3 ms | 256 KB |
01-10.txt | AC | 4 ms | 256 KB |
02-01.txt | AC | 93 ms | 6656 KB |
02-02.txt | AC | 93 ms | 6144 KB |
02-03.txt | AC | 94 ms | 6144 KB |
02-04.txt | AC | 94 ms | 6144 KB |
02-05.txt | AC | 91 ms | 6144 KB |
02-06.txt | AC | 92 ms | 6144 KB |
02-07.txt | AC | 89 ms | 5120 KB |
02-08.txt | AC | 94 ms | 6656 KB |
02-09.txt | AC | 97 ms | 6400 KB |
02-10.txt | AC | 55 ms | 1664 KB |
02-11.txt | AC | 69 ms | 2176 KB |
02-12.txt | AC | 88 ms | 4352 KB |
02-13.txt | AC | 85 ms | 5504 KB |
02-14.txt | AC | 92 ms | 6528 KB |
sample-01.txt | AC | 1 ms | 256 KB |
sample-02.txt | AC | 1 ms | 256 KB |