Submission #1870634


Source Code Expand

#include <bits/stdc++.h>
#define rank tipa_rank
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define INF 1000000000
#define EPS 1e-6
#define free tipa_free
#define EPS2 1e-8
using namespace std;
const ll MOD = INF + 7;
using namespace std;
ll ans = 0;
int n , m;
int visited[100000];
ll trees , cycles , free;
vector<vector<int> > g(100000);
int edgesCnt = 0 , verticesCnt;
bool bipatride;
void dfs(int u)
{
	for(int i = 0; i < g[u].size(); i++)
	{
		edgesCnt++;
		int v = g[u][i];
		bool Dfs = false;
		if(!visited[v])
			Dfs = true;
		if(visited[u] == 1)
		{
			if(visited[v] == 1)
				bipatride = false;
			visited[v] = 2;
		}
		if(visited[u] == 2)
		{
			if(visited[v] == 2)
				bipatride = false;
			visited[v] = 1;
		}
		if(Dfs)
			dfs(v);
	}
}
int main()
{
	scanf("%d %d" , &n , &m);
	for(int i = 0; i < m; i++)
	{
		int u , v;
		scanf("%d %d" , &u , &v);
		u--;v--;
		g[u].pb(v);
		g[v].pb(u);
	}
	for(int i = 0; i < n; i++)
	{
		if(!visited[i])
		{
			edgesCnt = 0;
			bipatride = true;
			visited[i] = 1;
			//edgesCnt++;
			dfs(i);
			if(!edgesCnt)
				free++;
			else if(bipatride)
			{
				trees++;
			}
			else
				cycles++;
		}
	}
	//cout << trees << " " << cycles << " " << free << endl;
	int x = n * 2 - 1;
	for(int i = 0; i < free; i++)
	{
		ans += x;
		x -= 2;
	}
	ans += cycles * (trees + cycles) + trees * (cycles + 2 * trees);
	cout << ans;
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:48:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d" , &n , &m);
                          ^
./Main.cpp:52:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d" , &u , &v);
                           ^

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 2944 KB
in11.txt AC 2 ms 2560 KB
in12.txt AC 19 ms 6016 KB
in13.txt AC 20 ms 6144 KB
in14.txt AC 39 ms 6144 KB
in15.txt AC 6 ms 3328 KB
in16.txt AC 29 ms 4608 KB
in17.txt AC 23 ms 5504 KB
in18.txt AC 55 ms 6784 KB
in19.txt AC 39 ms 6528 KB
in2.txt AC 2 ms 2560 KB
in20.txt AC 43 ms 6656 KB
in21.txt AC 73 ms 8960 KB
in22.txt AC 51 ms 5888 KB
in23.txt AC 37 ms 4864 KB
in24.txt AC 3 ms 2944 KB
in25.txt AC 79 ms 8960 KB
in26.txt AC 2 ms 2560 KB
in27.txt AC 3 ms 2688 KB
in28.txt AC 79 ms 8960 KB
in3.txt AC 2 ms 2560 KB
in4.txt AC 2 ms 2560 KB
in5.txt AC 53 ms 5632 KB
in6.txt AC 5 ms 3328 KB
in7.txt AC 5 ms 3072 KB
in8.txt AC 9 ms 3840 KB
in9.txt AC 24 ms 4736 KB
sample1.txt AC 2 ms 2560 KB
sample2.txt AC 2 ms 2560 KB