Submission #497195

# Submission time Handle Problem Language Result Execution time Memory
497195 2021-12-22T16:33:24 Z CyberCow Shymbulak (IZhO14_shymbulak) C++17
0 / 100
1500 ms 9844 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <stack>
#include <deque>
using namespace std;
using ll = long long;
vector<int> v[200004];
queue<int> q;
int color[200004], ans = 0, n, ma, c[200004];

void Dfs(int a, int qan)
{
	if (qan == ma)
	{
		ans++;
		return;
	}
	color[a] = 1;
	for (int to: v[a])
	{
		if (!color[to] && qan + 1 == c[to])
			Dfs(to, qan + 1);
	}
	color[a] = 0;
}

void solve()
{
	int i, j, x, y, oo = 1000000000;
	cin >> n;
	for ( i = 0; i < n; i++)
	{
		cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	color[1] = 1;
	q.push(1);
	while (!q.empty())
	{
		x = q.front();
		q.pop();
		for ( i = 0; i < v[x].size(); i++)
		{
			if (!color[v[x][i]])
			{
				color[v[x][i]] = color[x] + 1;
				q.push(v[x][i]);
			}
		}
	}
	int ind = 0;
	for ( i = 1; i <= n; i++)
	{
		if (color[i] > ma)
		{
			ma = color[i];
			ind = i;
		}
		color[i] = 0;
	}
	color[ind] = 1;
	q.push(ind);
	while (!q.empty())
	{
		x = q.front();
		q.pop();
		for (i = 0; i < v[x].size(); i++)
		{
			if (!color[v[x][i]])
			{
				color[v[x][i]] = color[x] + 1;
				q.push(v[x][i]);
			}
		}
	}
	ma = 0;
	for (i = 1; i <= n; i++)
	{
		ma = max(ma, color[i]);
		color[i] = 0;
	}
	for ( j = 1; j <= n; j++)
	{
		c[j] = 1;
		q.push(j);
		while (!q.empty())
		{
			x = q.front();
			q.pop();
			for (i = 0; i < v[x].size(); i++)
			{
				if (!c[v[x][i]])
				{
					c[v[x][i]] = c[x] + 1;
					q.push(v[x][i]);
				}
			}
		}
		Dfs(j, 1);
		for ( i = 1; i <= n; i++)
		{
			c[i] = 0;
		}
	}
	cout << ans / 2;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tt = 1;
	//cin >> tt;
	while (tt--)
	{
		solve();
	}
	return 0;
}

Compilation message

shymbulak.cpp: In function 'void solve()':
shymbulak.cpp:54:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for ( i = 0; i < v[x].size(); i++)
      |                ~~^~~~~~~~~~~~~
shymbulak.cpp:79:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |   for (i = 0; i < v[x].size(); i++)
      |               ~~^~~~~~~~~~~~~
shymbulak.cpp:102:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |    for (i = 0; i < v[x].size(); i++)
      |                ~~^~~~~~~~~~~~~
shymbulak.cpp:40:18: warning: unused variable 'oo' [-Wunused-variable]
   40 |  int i, j, x, y, oo = 1000000000;
      |                  ^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5024 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5024 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 2 ms 4944 KB Output is correct
7 Correct 3 ms 4944 KB Output is correct
8 Correct 2 ms 4944 KB Output is correct
9 Correct 2 ms 5020 KB Output is correct
10 Correct 3 ms 5024 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 4 ms 5020 KB Output is correct
14 Correct 10 ms 5016 KB Output is correct
15 Incorrect 11 ms 4944 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 5076 KB Output is correct
2 Correct 14 ms 5072 KB Output is correct
3 Incorrect 31 ms 5064 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1565 ms 9844 KB Time limit exceeded
2 Halted 0 ms 0 KB -