96142024-02-23 14:34:28Vkrisztian01Hálózati átvitelcpp17Time limit exceeded 41/50638ms16176 KiB
#include <iostream>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>

using namespace std;

int n,m,k,h,a,b,c,tav,lepes,csucs,index;
vector<int>ki;
vector<vector<int> > dp;
vector<vector<pair<int,int> > > g;
set<pair<int,pair<int,int> > > seged;

int main()
{
    cin.tie(0);
	ios::sync_with_stdio(false);
    cin>>n>>m>>k>>h;
    ki.assign(n+1,-1);
    dp.assign(n+1,vector<int>(h+1,0));
    g.resize(n+1);
    while(m--)
    {
        cin>>a>>b>>c;
        g[a].push_back(make_pair(b,c));
        g[b].push_back(make_pair(a,c));
    }
    dp[k]=vector<int>(h+1,1e9);
    seged.insert(make_pair(1e9,make_pair(0,k)));
    while(!seged.empty())
    {
        tav=seged.begin()->first;
        lepes=seged.begin()->second.first;
        csucs=seged.begin()->second.second;
        seged.erase(seged.begin());
        if(dp[csucs][lepes]>tav) continue;
        if(ki[csucs]==-1) ki[csucs]=tav;
        else ki[csucs]=max(ki[csucs],tav);
        if(lepes==h) continue;
        for(auto to:g[csucs])
        {
            a=min(tav,to.second);
            if(dp[to.first][lepes+1]>=a) continue;
            index=lepes+1;
            while(index<=h && dp[to.first][index]<a)
            {
                dp[to.first][index]=a;
                ++index;
            }
            seged.insert(make_pair(a,make_pair(lepes+1,to.first)));
        }

    }
    ki[k]=0;
    for(int i=1;i<=n;i++) cout<<ki[i]<<"\n";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base41/50
1Accepted0/03ms1828 KiB
2Accepted0/04ms2180 KiB
3Accepted1/13ms2148 KiB
4Accepted1/13ms2332 KiB
5Accepted2/23ms2684 KiB
6Accepted2/24ms2908 KiB
7Accepted2/24ms3236 KiB
8Accepted2/24ms3448 KiB
9Accepted1/14ms3932 KiB
10Accepted1/137ms3920 KiB
11Accepted1/1144ms4144 KiB
12Accepted1/1156ms4068 KiB
13Accepted2/2171ms4212 KiB
14Accepted2/2212ms4276 KiB
15Accepted2/2474ms4696 KiB
16Accepted2/2360ms4628 KiB
17Accepted2/2407ms4796 KiB
18Accepted2/2513ms5076 KiB
19Accepted2/2474ms4880 KiB
20Accepted2/2425ms4976 KiB
21Accepted1/1423ms12640 KiB
22Time limit exceeded0/1577ms7636 KiB
23Time limit exceeded0/1570ms7860 KiB
24Time limit exceeded0/1566ms8268 KiB
25Time limit exceeded0/2558ms9048 KiB
26Time limit exceeded0/2583ms9008 KiB
27Time limit exceeded0/2638ms9104 KiB
28Accepted2/2196ms14684 KiB
29Accepted2/2246ms15924 KiB
30Accepted2/2248ms15916 KiB
31Accepted2/2252ms16136 KiB
32Accepted2/2244ms16176 KiB