Submission #1870518


Source Code Expand

#include <bits/stdc++.h>
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 LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 100100;

VI g[MAX];

int U[MAX];
int C[MAX];

int sz;

bool dfs(int x, int c)
{
	U[x] = true;

	C[x] = c;

	int res = false;
	sz++;

	FOR (i, 0, SZ(g[x]))
	{
		int to = g[x][i];
		if (U[to])
		{
			if (C[to] == C[x]) res = true;
		}
		else
		{
			if (dfs(to, c ^ 1)) res = true;
		}
	}

	return res;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n, m;
	scanf("%d%d", &n, &m);
	FOR (i, 0, m)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		x--;
		y--;

		g[x].PB(y);
		g[y].PB(x);
	}

	LL c1 = 0;
	LL c[2] = {0, 0};

	FOR (i, 0, n)
	{
		if (!U[i])
		{
			sz = 0;
			int r = dfs(i, 0);

			if (sz == 1) c1++;
			else c[r]++;
		}
	}

	LL res = 0;
	res += c1 * c1;


	res += (n-c1) * c1 * 2;

	res += c[1] * c[1];
	res += c[1] * c[0] * 2;
	res += c[0] * c[0] * 2;

	cout<<res<<endl;

}

Submission Info

Submission Time
Task C - Squared Graph
User vjudge5
Language C++14 (GCC 5.4.1)
Score 800
Code Size 1411 Byte
Status AC
Exec Time 81 ms
Memory 12160 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:62:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
                       ^
./Main.cpp:66:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &x, &y);
                        ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 2
AC × 32
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 2 ms 2560 KB
in10.txt AC 3 ms 3328 KB
in11.txt AC 2 ms 2560 KB
in12.txt AC 21 ms 6528 KB
in13.txt AC 21 ms 6528 KB
in14.txt AC 39 ms 6528 KB
in15.txt AC 6 ms 3712 KB
in16.txt AC 29 ms 4992 KB
in17.txt AC 24 ms 6272 KB
in18.txt AC 54 ms 8064 KB
in19.txt AC 43 ms 8192 KB
in2.txt AC 2 ms 2560 KB
in20.txt AC 43 ms 8320 KB
in21.txt AC 80 ms 12160 KB
in22.txt AC 51 ms 6272 KB
in23.txt AC 37 ms 4864 KB
in24.txt AC 4 ms 3456 KB
in25.txt AC 81 ms 12160 KB
in26.txt AC 3 ms 2560 KB
in27.txt AC 3 ms 2688 KB
in28.txt AC 80 ms 12160 KB
in3.txt AC 2 ms 2560 KB
in4.txt AC 3 ms 2560 KB
in5.txt AC 53 ms 6144 KB
in6.txt AC 6 ms 3712 KB
in7.txt AC 5 ms 3584 KB
in8.txt AC 9 ms 4224 KB
in9.txt AC 25 ms 5760 KB
sample1.txt AC 2 ms 2560 KB
sample2.txt AC 2 ms 2560 KB