10892022-02-28 15:20:50batorfibalazsHálózati átvitelcpp14Wrong answer 4/50592ms7456 KiB
#include <bits/stdc++.h>
using namespace std;


void kereso(int elozo);

int cs[10000];
int utak[100][10000][2]={}; //1. hova, 2. sebessege az utnak
int szamlalo[10000]={};
int sz, csomo, csat, h;
map <int, int> holtart;
int s[10000];
bool nullae[10000];

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> sz >> csat >> csomo >> h;
    int s1,s2,s3;
    for (int i=0;i<csat;i++)
    {
        cin >> s1 >> s2 >> s3;
        s1--;
        s2--;
        utak[szamlalo[s1]][s1][0]=s2;
        utak[szamlalo[s2]][s2][0]=s1;
        utak[szamlalo[s1]][s1][1]=s3;
        utak[szamlalo[s2]][s2][1]=s3;
        szamlalo[s1]++;
        szamlalo[s2]++;
    }
    ///////////////////
    /*for (int i=0;i<sz;i++)
    {
        for (int j=0;j<szamlalo[i];j++)
        {
            cout << utak[j][i][0] << " " << utak[j][i][1] << "  ";
        }
        cout << szamlalo[i] << endl;
    }*/
    ///////////////////
    int hany=0;
    s1=1;
    s[0]=csomo-1;
    do
    {
        holtart.clear();
        hany++;
        for (int i=0;i<s1;i++)
        {
            kereso(s[i]);
        }
        s1=0;
        for (auto t:holtart)
        {
            s[s1]=t.first;
            s1++;
        }

    } while (holtart.size()!=0 and hany<h);
    cs[csomo-1]=0;
    nullae[csomo-1]=true;
    //kiiras
    for (int i=0;i<sz;i++)
    {
        if (cs[i]==0 and !nullae[i]) cout << -1 << endl;
        else cout << cs[i] << endl;
    }
    return 0;
}

void kereso(int elozo)
{

    for (int i=0;i<szamlalo[elozo];i++)
    {
        holtart[utak[i][elozo][0]]++;

        if (cs[elozo]<utak[i][elozo][1] and elozo!=csomo-1)
        {
            if (cs[utak[i][elozo][0]]<=cs[elozo])
            {
                cs[utak[i][elozo][0]]=cs[elozo];
                if (cs[elozo]==0)
                {
                    nullae[utak[i][elozo][0]]=true;
                }
            }
        }
        else
        {
            if (cs[utak[i][elozo][0]]<=utak[i][elozo][1])
            {
                cs[utak[i][elozo][0]]=utak[i][elozo][1];
                if (utak[i][elozo][1]==0)
                {
                    nullae[utak[i][elozo][0]]=true;
                }
            }
        }
    }
}





/*
5 6 1 2
1 2 2
1 5 4
1 3 2
1 4 3
5 4 1
5 3 4

5 1 1 1
1 2 3
*/
SubtaskSumTestVerdictTimeMemory
base4/50
1Accepted0/02ms1988 KiB
2Wrong answer0/02ms2140 KiB
3Accepted1/11ms2000 KiB
4Wrong answer0/11ms2012 KiB
5Wrong answer0/22ms2040 KiB
6Wrong answer0/22ms2204 KiB
7Wrong answer0/22ms2276 KiB
8Wrong answer0/22ms2284 KiB
9Wrong answer0/14ms2280 KiB
10Wrong answer0/110ms2340 KiB
11Accepted1/123ms2572 KiB
12Wrong answer0/119ms2820 KiB
13Wrong answer0/221ms2676 KiB
14Wrong answer0/225ms2904 KiB
15Wrong answer0/279ms3404 KiB
16Wrong answer0/245ms3504 KiB
17Wrong answer0/259ms3524 KiB
18Wrong answer0/2105ms3784 KiB
19Wrong answer0/289ms3804 KiB
20Wrong answer0/259ms4008 KiB
21Accepted1/1238ms5176 KiB
22Wrong answer0/1358ms5740 KiB
23Accepted1/1479ms6212 KiB
24Time limit exceeded0/1570ms4384 KiB
25Time limit exceeded0/2582ms4628 KiB
26Time limit exceeded0/2555ms4904 KiB
27Time limit exceeded0/2592ms5116 KiB
28Runtime error0/24ms6236 KiB
29Runtime error0/24ms6512 KiB
30Runtime error0/26ms6788 KiB
31Runtime error0/24ms7040 KiB
32Runtime error0/24ms7456 KiB