Submission #4065196


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

vector<ll> G[101010];
vector<ll> mark(101010, -1);

bool is_bipartite(ll now, ll now_mark){
	if(mark[now]!=-1) return (mark[now]==now_mark);
	mark[now] = now_mark;
	bool flag = true;
	REP(i, G[now].size()){
		ll next = G[now][i];
		flag &= is_bipartite(next, 1-now_mark);
	}
	return flag;
}

int main(){
	ll N, M;
	cin >> N >> M;
	REP(i, M){
		ll a, b;
		cin >> a >> b;
		a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	bool flag = is_bipartite(0, 1);
	if(flag){
		ll sum = 0;
		REP(i, N) sum += mark[i];
		ll res = 0;
		REP(i, N){
			if(mark[i]==0){
				res += (sum - G[i].size());
			}
		}
		cout << res << endl;
	}else{
		cout << N*(N-1)/2 - M << endl;
	}

    return 0;
}

Submission Info

Submission Time
Task C - 3 Steps
User theory_and_me
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1273 Byte
Status AC
Exec Time 83 ms
Memory 8448 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 28
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 3456 KB
01-02.txt AC 3 ms 3456 KB
01-03.txt AC 3 ms 3456 KB
01-04.txt AC 3 ms 3456 KB
01-05.txt AC 3 ms 3456 KB
01-06.txt AC 4 ms 3456 KB
01-07.txt AC 3 ms 3456 KB
01-08.txt AC 3 ms 3456 KB
01-09.txt AC 4 ms 3456 KB
01-10.txt AC 5 ms 3584 KB
02-01.txt AC 81 ms 8320 KB
02-02.txt AC 80 ms 7040 KB
02-03.txt AC 80 ms 7040 KB
02-04.txt AC 83 ms 7040 KB
02-05.txt AC 83 ms 7040 KB
02-06.txt AC 83 ms 7040 KB
02-07.txt AC 77 ms 8448 KB
02-08.txt AC 81 ms 8448 KB
02-09.txt AC 81 ms 7552 KB
02-10.txt AC 47 ms 6144 KB
02-11.txt AC 60 ms 6400 KB
02-12.txt AC 77 ms 7424 KB
02-13.txt AC 75 ms 7168 KB
02-14.txt AC 83 ms 7680 KB
sample-01.txt AC 3 ms 3456 KB
sample-02.txt AC 3 ms 3456 KB