Submission #135039

# Submission time Handle Problem Language Result Execution time Memory
135039 2019-07-23T14:50:54 Z Lawliet Duathlon (APIO18_duathlon) C++14
8 / 100
90 ms 12272 KB
#include <bits/stdc++.h>

#define MAX 100010

using namespace std;
typedef long long int lli;

int n, m;
int n1, n2;

lli ans;

int ingrau[MAX];

bool marc[MAX];

vector<int> grafo[MAX];

bool DFS(int i, int p, int& sz)
{
	marc[i] = true;

	sz++;

	for(int g = 0 ; g < grafo[i].size() ; g++)
	{
		int prox = grafo[i][g];

		if(marc[prox]) continue;

		DFS(prox , i , sz);
	}
}

int main()
{
	scanf("%d %d",&n,&m);

	for(int g = 0 ; g < m ; g++)
	{
		scanf("%d %d",&n1,&n2);

		grafo[n1].push_back(n2);
		grafo[n2].push_back(n1);

		ingrau[n1]++;
		ingrau[n2]++;
	}

	lli line = 0;
	lli cycle = 0;

	for(int g = 1 ; g <= n ; g++)
	{
		if(ingrau[g] == 1 && !marc[g])
		{
			int size = 0;

			DFS(g , g , size);

			for(int k = 0 ; k < size ; k++)
			{
				lli sum = size - k - 1;
				sum *= size - k - 2;

				sum /= 2;

				line += 2*sum;
			}
		}
	}

	for(int g = 1 ; g <= n ; g++)
	{
		if(marc[g]) continue;

		int size = 0;

		DFS(g , g , size);

		lli result = size;
		result *= size - 1;
		result *= size - 2;

		cycle += result;
	}

	printf("%lld\n",cycle + line);
}

Compilation message

count_triplets.cpp: In function 'bool DFS(int, int, int&)':
count_triplets.cpp:25:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int g = 0 ; g < grafo[i].size() ; g++)
                  ~~^~~~~~~~~~~~~~~~~
count_triplets.cpp:33:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~
count_triplets.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&n1,&n2);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2748 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
6 Correct 4 ms 2808 KB Output is correct
7 Incorrect 4 ms 2680 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2748 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
6 Correct 4 ms 2808 KB Output is correct
7 Incorrect 4 ms 2680 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 85 ms 11256 KB Output is correct
2 Correct 79 ms 12272 KB Output is correct
3 Correct 83 ms 9820 KB Output is correct
4 Correct 77 ms 11100 KB Output is correct
5 Correct 90 ms 9080 KB Output is correct
6 Correct 78 ms 10144 KB Output is correct
7 Correct 80 ms 8696 KB Output is correct
8 Correct 85 ms 9268 KB Output is correct
9 Correct 77 ms 8028 KB Output is correct
10 Correct 79 ms 8392 KB Output is correct
11 Correct 61 ms 7316 KB Output is correct
12 Correct 63 ms 7288 KB Output is correct
13 Correct 61 ms 7080 KB Output is correct
14 Correct 60 ms 7032 KB Output is correct
15 Correct 42 ms 6392 KB Output is correct
16 Correct 45 ms 6368 KB Output is correct
17 Correct 5 ms 3192 KB Output is correct
18 Correct 6 ms 3192 KB Output is correct
19 Correct 5 ms 3192 KB Output is correct
20 Correct 5 ms 3192 KB Output is correct
21 Correct 5 ms 3192 KB Output is correct
22 Correct 5 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 6660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 73 ms 6428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2748 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
6 Correct 4 ms 2808 KB Output is correct
7 Incorrect 4 ms 2680 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2748 KB Output is correct
5 Correct 4 ms 2680 KB Output is correct
6 Correct 4 ms 2808 KB Output is correct
7 Incorrect 4 ms 2680 KB Output isn't correct
8 Halted 0 ms 0 KB -