Submission #372860

# Submission time Handle Problem Language Result Execution time Memory
372860 2021-03-02T04:43:03 Z sam571128 Janjetina (COCI21_janjetina) C++14
15 / 110
1500 ms 9836 KB
#include <bits/stdc++.h>

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 1e5+5;
vector<pair<int,int>> adj[N];
int ans = 0;
int dis[N], mx[N];

void dfs(int u, int par){
	for(auto [v,w] : adj[u]){
		if(v==par) continue;
		dis[v] = dis[u]+1;
		mx[v] = max(mx[u],w);
		dfs(v,u);
	}
}

signed main(){
	fastio
	int n,k;
	cin >> n >> k;
	for(int i = 0;i < n-1;i++){
		int u,v,w;
		cin >> u >> v >> w;
		adj[u].push_back({v,w});
		adj[v].push_back({u,w});
	}

	for(int i = 1;i <= n;i++){
		fill(mx,mx+n+1,0);
		dis[i] = 0;
		dfs(i,-1);
		for(int j = 1;j <= n;j++){
			if(mx[j]-dis[j] >= k&&i!=j){
				ans++;
			}
		}
	}
	cout << ans << "\n";
}

Compilation message

Main.cpp: In function 'void dfs(long long int, long long int)':
Main.cpp:14:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   14 |  for(auto [v,w] : adj[u]){
      |           ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 13 ms 2796 KB Output is correct
5 Correct 13 ms 2796 KB Output is correct
6 Correct 13 ms 2796 KB Output is correct
7 Correct 13 ms 2796 KB Output is correct
8 Correct 13 ms 2796 KB Output is correct
9 Correct 14 ms 2796 KB Output is correct
10 Correct 14 ms 2796 KB Output is correct
11 Correct 15 ms 2796 KB Output is correct
12 Correct 18 ms 2796 KB Output is correct
13 Correct 18 ms 2816 KB Output is correct
14 Correct 18 ms 2796 KB Output is correct
15 Correct 18 ms 2796 KB Output is correct
16 Correct 19 ms 2796 KB Output is correct
17 Correct 18 ms 2796 KB Output is correct
18 Correct 18 ms 2796 KB Output is correct
19 Correct 18 ms 2796 KB Output is correct
20 Correct 17 ms 2796 KB Output is correct
21 Correct 18 ms 2796 KB Output is correct
22 Correct 18 ms 2796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 13 ms 2796 KB Output is correct
5 Correct 1094 ms 4076 KB Output is correct
6 Execution timed out 1542 ms 9836 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 13 ms 2796 KB Output is correct
5 Correct 13 ms 2796 KB Output is correct
6 Correct 13 ms 2796 KB Output is correct
7 Correct 13 ms 2796 KB Output is correct
8 Correct 13 ms 2796 KB Output is correct
9 Correct 14 ms 2796 KB Output is correct
10 Correct 14 ms 2796 KB Output is correct
11 Correct 15 ms 2796 KB Output is correct
12 Correct 18 ms 2796 KB Output is correct
13 Correct 18 ms 2816 KB Output is correct
14 Correct 18 ms 2796 KB Output is correct
15 Correct 18 ms 2796 KB Output is correct
16 Correct 19 ms 2796 KB Output is correct
17 Correct 18 ms 2796 KB Output is correct
18 Correct 18 ms 2796 KB Output is correct
19 Correct 18 ms 2796 KB Output is correct
20 Correct 17 ms 2796 KB Output is correct
21 Correct 18 ms 2796 KB Output is correct
22 Correct 18 ms 2796 KB Output is correct
23 Correct 2 ms 2668 KB Output is correct
24 Correct 2 ms 2668 KB Output is correct
25 Correct 2 ms 2668 KB Output is correct
26 Correct 13 ms 2796 KB Output is correct
27 Correct 1094 ms 4076 KB Output is correct
28 Execution timed out 1542 ms 9836 KB Time limit exceeded
29 Halted 0 ms 0 KB -