96202024-02-23 14:45:05Vkrisztian01Hálózati átvitelcpp17Time limit exceeded 41/50578ms15212 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;
priority_queue<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.push(make_pair(-1*1e9,make_pair(-1*0,k)));
    while(!seged.empty())
    {
        tav=-1*seged.top().first;
        lepes=-1*seged.top().second.first;
        csucs=seged.top().second.second;
        seged.pop();
        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.push(make_pair(-1*a,make_pair(-1*(lepes+1),to.first)));
        }

    }
    ki[k]=0;
    for(int i=1;i<=n;i++) cout<<ki[i]<<"\n";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base41/50
1Accepted0/03ms1824 KiB
2Accepted0/03ms2216 KiB
3Accepted1/13ms2400 KiB
4Accepted1/13ms2496 KiB
5Accepted2/23ms2584 KiB
6Accepted2/24ms2652 KiB
7Accepted2/24ms2584 KiB
8Accepted2/24ms2888 KiB
9Accepted1/14ms3384 KiB
10Accepted1/132ms3576 KiB
11Accepted1/1125ms3796 KiB
12Accepted1/1129ms3812 KiB
13Accepted2/2143ms3768 KiB
14Accepted2/2194ms4072 KiB
15Accepted2/2411ms4444 KiB
16Accepted2/2330ms4244 KiB
17Accepted2/2386ms4420 KiB
18Accepted2/2460ms4728 KiB
19Accepted2/2421ms4440 KiB
20Accepted2/2358ms4420 KiB
21Accepted1/1375ms11980 KiB
22Time limit exceeded0/1578ms7052 KiB
23Time limit exceeded0/1554ms6912 KiB
24Time limit exceeded0/1563ms7220 KiB
25Time limit exceeded0/2559ms7836 KiB
26Time limit exceeded0/2578ms7896 KiB
27Time limit exceeded0/2565ms8328 KiB
28Accepted2/2204ms13468 KiB
29Accepted2/2257ms14588 KiB
30Accepted2/2259ms14900 KiB
31Accepted2/2261ms15212 KiB
32Accepted2/2256ms15068 KiB