Submission #1880271
Source Code Expand
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;
const int MAX = 100000 + 47;
const int MOD = 1000 * 1000 * 1000 + 7;
vector<int> g[MAX];
int C[MAX];
int numb;
bool is;
LL o, e, iz;
void dfs(int v, int c)
{
if (C[v] != -1)
{
if (C[v] != c) is = false;
return;
}
numb++;
C[v] = c;
FOR(i, 0, SZ(g[v]))
{
int to = g[v][i];
dfs(to, c ^ 1);
}
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
ios::sync_with_stdio(false); cin.tie(0);
int n, m;
cin >> n >> m;
FOR(i, 0, m)
{
int a, b;
cin >> a >> b;
a--;
b--;
g[a].push_back(b);
g[b].push_back(a);
}
FILL(C, -1);
FOR(i, 0, n)
{
if (C[i] == -1)
{
numb = 0;
is = true;
dfs(i, 0);
if (numb == 1)
{
iz++;
continue;
}
if (is) e++; else o++;
}
}
//cout << res << endl;
LL res = 2 * e * e + o * o + 2 * o * e + n * iz + iz * (n - iz);
cout << res << endl;
}
Submission Info
Submission Time |
|
Task |
C - Squared Graph |
User |
vjudge1 |
Language |
C++14 (Clang 3.8.0) |
Score |
800 |
Code Size |
1797 Byte |
Status |
AC |
Exec Time |
371 ms |
Memory |
9984 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
800 / 800 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample1.txt, sample2.txt |
All |
sample1.txt, sample2.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt |
Case Name |
Status |
Exec Time |
Memory |
in1.txt |
AC |
8 ms |
3576 KB |
in10.txt |
AC |
3 ms |
2944 KB |
in11.txt |
AC |
3 ms |
2944 KB |
in12.txt |
AC |
87 ms |
6144 KB |
in13.txt |
AC |
87 ms |
6144 KB |
in14.txt |
AC |
172 ms |
6144 KB |
in15.txt |
AC |
16 ms |
3328 KB |
in16.txt |
AC |
129 ms |
4608 KB |
in17.txt |
AC |
97 ms |
5632 KB |
in18.txt |
AC |
235 ms |
7040 KB |
in19.txt |
AC |
176 ms |
7040 KB |
in2.txt |
AC |
3 ms |
2944 KB |
in20.txt |
AC |
177 ms |
7040 KB |
in21.txt |
AC |
357 ms |
9984 KB |
in22.txt |
AC |
292 ms |
6272 KB |
in23.txt |
AC |
244 ms |
5248 KB |
in24.txt |
AC |
4 ms |
3072 KB |
in25.txt |
AC |
371 ms |
9984 KB |
in26.txt |
AC |
3 ms |
2944 KB |
in27.txt |
AC |
4 ms |
3072 KB |
in28.txt |
AC |
360 ms |
9984 KB |
in3.txt |
AC |
3 ms |
2944 KB |
in4.txt |
AC |
3 ms |
2944 KB |
in5.txt |
AC |
275 ms |
5760 KB |
in6.txt |
AC |
12 ms |
3328 KB |
in7.txt |
AC |
14 ms |
3200 KB |
in8.txt |
AC |
31 ms |
3840 KB |
in9.txt |
AC |
102 ms |
4992 KB |
sample1.txt |
AC |
2 ms |
2944 KB |
sample2.txt |
AC |
2 ms |
2944 KB |