43482023-03-26 10:40:39horvathabelHálózati átvitelcpp17Wrong answer 0/5059ms10472 KiB
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> g[100001];
bool seen[100001];
void dfs(int x, int dist, int h){
	if (!seen[x] && dist<=h){
		seen[x]=true; 
		for (pair<int, int> edge:g[x]){
			if (!seen[edge.first]) dfs(edge.first, dist+1, h);
		}
	}
}
int main() {
	int n,m,k,h;
	cin>>n>>m>>k>>h;
	for (int i=0; i<m;i++){
		int x,y,c;
		cin>>x>>y>>c; 
		g[x].push_back({y,c});
		g[y].push_back({x,c});
	}
	vector<int> dp;
	dp.assign(n+1,0);
	dfs(k,0,h);
	for (auto edge:g[k]){
		dp[edge.first]=edge.second;
	}
	for (int j=1; j<=h;j++){
		for (int i=1; i<=n;i++){
			for (pair<int, int> edge:g[i]){
				dp[edge.first]=max(dp[edge.first], min(dp[i], edge.second));
			}
		}
	}
	for (int i=1; i<=n;i++){
		if (i==k) cout<<0<<endl; 
		else{
			if (!seen[i]) cout<<-1<<endl;
			else cout<<dp[i]<<endl;
		}
	} 
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Accepted0/04ms6464 KiB
2Wrong answer0/04ms6820 KiB
3Wrong answer0/14ms7012 KiB
4Wrong answer0/14ms7180 KiB
5Wrong answer0/24ms7500 KiB
6Wrong answer0/24ms7724 KiB
7Wrong answer0/26ms7960 KiB
8Wrong answer0/24ms7804 KiB
9Wrong answer0/17ms7964 KiB
10Wrong answer0/17ms8172 KiB
11Wrong answer0/19ms8580 KiB
12Wrong answer0/110ms8608 KiB
13Wrong answer0/29ms8540 KiB
14Wrong answer0/212ms8744 KiB
15Wrong answer0/217ms8808 KiB
16Wrong answer0/217ms9092 KiB
17Wrong answer0/217ms9012 KiB
18Wrong answer0/217ms9056 KiB
19Wrong answer0/217ms9180 KiB
20Wrong answer0/216ms9120 KiB
21Wrong answer0/135ms9460 KiB
22Wrong answer0/141ms9796 KiB
23Wrong answer0/146ms10004 KiB
24Wrong answer0/150ms10172 KiB
25Wrong answer0/257ms10088 KiB
26Wrong answer0/254ms10076 KiB
27Wrong answer0/259ms10324 KiB
28Wrong answer0/243ms10264 KiB
29Wrong answer0/254ms10264 KiB
30Wrong answer0/250ms10296 KiB
31Wrong answer0/250ms10396 KiB
32Wrong answer0/254ms10472 KiB