Submission #808760

# Submission time Handle Problem Language Result Execution time Memory
808760 2023-08-05T10:40:57 Z tlnk07 Janjetina (COCI21_janjetina) C++17
0 / 110
1500 ms 428 KB
#include<bits/stdc++.h>
using namespace std;

long long n, k, cnt = 0, sum, height;
vector<pair<int, int>> vec[1001];
bool check = 0;

void dfs(int x, int y, int p, int len, int h)
{
	if(x == y)
	{
		sum = len;
		height = h;
		check = true;
		return;
	}
	for(pair<int, int> c : vec[x])	
	{
		if(c.first != p)	dfs(c.first, y, x, max(len, c.second), h + 1);
		if(check)	return;
	}
}

int main()
{
	cin >> n >> k;
	for(int i = 1; i < n; ++i)
	{
		long long x, y, z;
		cin >> x >> y >> z;
		vec[x].push_back({y, z});
		vec[y].push_back({x, z});
	}
	for(int i = 1; i <= n; ++i)
	{
		for(int j = i + 1; j <= n; ++j)
		{
			check = height = sum = 0;
			dfs(i, j, 0, 0, 0);
			if(sum - height >= k)
			{
				++cnt;
			}
		}
	}
	cout << cnt * 2;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:38:19: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   38 |    check = height = sum = 0;
      |            ~~~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Execution timed out 1570 ms 340 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Execution timed out 1573 ms 428 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Execution timed out 1570 ms 340 KB Time limit exceeded
5 Halted 0 ms 0 KB -