96092024-02-23 14:28:43Vkrisztian01Hálózati átvitelcpp17Time limit exceeded 22/50646ms16016 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>>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,0);
    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;
        index=lepes;
        while(index<=h && dp[csucs][index]<tav)
        {
            dp[csucs][index]=tav;
            ++index;
        }
        if(ki[csucs]==-1) ki[csucs]=tav;
        else ki[csucs]=max(ki[csucs],tav);
        if(lepes==h) continue;
        for(auto to:g[csucs])
        {
            if(dp[to.first][lepes+1]>=min(tav,to.second)) continue;
            seged.insert(make_pair(min(tav,to.second),make_pair(lepes+1,to.first)));
        }

    }
    ki[k]=0;
    for(int i=1;i<=n;i++) cout<<ki[i]<<"\n";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base22/50
1Accepted0/03ms1944 KiB
2Accepted0/04ms2112 KiB
3Accepted1/13ms2324 KiB
4Accepted1/13ms2664 KiB
5Accepted2/24ms2812 KiB
6Accepted2/213ms2860 KiB
7Accepted2/220ms2952 KiB
8Accepted2/219ms3180 KiB
9Accepted1/16ms3520 KiB
10Accepted1/165ms3712 KiB
11Time limit exceeded0/1563ms2808 KiB
12Time limit exceeded0/1586ms3236 KiB
13Time limit exceeded0/2569ms3324 KiB
14Time limit exceeded0/2558ms3480 KiB
15Time limit exceeded0/2555ms4024 KiB
16Time limit exceeded0/2646ms3696 KiB
17Time limit exceeded0/2582ms3844 KiB
18Time limit exceeded0/2558ms4244 KiB
19Time limit exceeded0/2569ms4036 KiB
20Time limit exceeded0/2554ms4296 KiB
21Time limit exceeded0/1569ms7960 KiB
22Time limit exceeded0/1559ms8016 KiB
23Time limit exceeded0/1563ms8024 KiB
24Time limit exceeded0/1554ms8292 KiB
25Time limit exceeded0/2574ms9304 KiB
26Time limit exceeded0/2574ms9176 KiB
27Time limit exceeded0/2565ms9404 KiB
28Accepted2/2441ms14652 KiB
29Accepted2/2532ms15744 KiB
30Accepted2/2518ms16016 KiB
31Accepted2/2501ms15912 KiB
32Accepted2/2549ms16008 KiB