43472023-03-26 10:36:30horvathabelHálózati átvitelcpp17Wrong answer 6/5064ms11328 KiB
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> g[100001];
bool seen[100001];
void dfs(int x){
	if (!seen[x]){
		seen[x]=true; 
		for (pair<int, int> edge:g[x]){
			if (!seen[edge.first]) dfs(edge.first);
		}
	}
}
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);
	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
base6/50
1Accepted0/04ms6336 KiB
2Wrong answer0/04ms6672 KiB
3Wrong answer0/14ms6620 KiB
4Wrong answer0/14ms6876 KiB
5Wrong answer0/24ms7092 KiB
6Wrong answer0/24ms7060 KiB
7Wrong answer0/24ms7084 KiB
8Wrong answer0/24ms7332 KiB
9Wrong answer0/16ms7444 KiB
10Wrong answer0/18ms7452 KiB
11Accepted1/19ms7748 KiB
12Wrong answer0/110ms8028 KiB
13Wrong answer0/28ms7928 KiB
14Wrong answer0/29ms8112 KiB
15Wrong answer0/216ms8580 KiB
16Wrong answer0/214ms8672 KiB
17Wrong answer0/216ms8616 KiB
18Wrong answer0/217ms8880 KiB
19Wrong answer0/217ms9168 KiB
20Wrong answer0/217ms9220 KiB
21Accepted1/141ms9564 KiB
22Wrong answer0/143ms10060 KiB
23Accepted1/146ms10372 KiB
24Accepted1/148ms10448 KiB
25Wrong answer0/257ms10652 KiB
26Wrong answer0/254ms10632 KiB
27Accepted2/264ms10980 KiB
28Wrong answer0/241ms11068 KiB
29Wrong answer0/245ms11072 KiB
30Wrong answer0/243ms11060 KiB
31Wrong answer0/243ms11048 KiB
32Wrong answer0/245ms11328 KiB