199942025-12-30 22:06:52VargaVivienVárosnézéscpp17Wrong answer 0/801.113s262144 KiB
#include <iostream>
#include <vector>
#include <string>

using namespace std;

struct ut
{
    int bol, ba;
};

int latogatas(int varos, int *latvanyossag, int *db, vector<vector<int>> terkep, int n, vector<int> &szam)
{
    bool vege = false;
    vector<int> maximum;
    vector<int> temp;
    int maxi = 0;
    int ch_v=0;
   // cout << "szam" << &szam << endl;
   // cout << "temp" << &temp << endl;
    if(varos == n)
    {
        vege = true;
        *db += latvanyossag[varos - 1];
        szam.push_back(varos);
        return *db;
    }
    else
    {
        int reszdb;
        //szam.push_back(varos);
        for(int i = 0; i < terkep[varos].size(); i++)
        {

            reszdb = *db + latvanyossag[varos - 1];
            temp.clear();

                if(latogatas(terkep[varos][i], latvanyossag, &reszdb, terkep, n, temp)>=0)
                {
                    vege = true;
                    if(reszdb > maxi)
                    {
                        maxi = reszdb;
                       ch_v=terkep[varos][i];
                    }
                }

        }
        if(!vege)
        {
            szam.pop_back();
        }
        else
        {
            //szam.insert(szam.end(), maximum.begin(), maximum.end());
            //szam=maximum;
            szam.push_back(varos);
            latogatas(ch_v, latvanyossag, &reszdb, terkep, n, szam);

        }
        *db = maxi;
        return *db;
    }
}

int main()
{
    int n, m;
    ut x;
    cin >> x.bol >> x.ba;
    n = x.bol;
    m = x.ba;
    int numbers[n];
    for(int i=0; i<n; i++) cin >> numbers[i];

    vector <vector<int>> terkep(n+1);

    for(int i = 0; i < m; i++)
    {
        cin >> x.bol >> x.ba;
        terkep[x.bol].push_back(x.ba);

    }
    int db = 0;
    vector<int> szam;
    if (latogatas(1, numbers, &db, terkep, n, szam)>=0)
    {
        cout << db << endl;
        //cout << szam.size()<< endl;
        for (int j=szam.size()-1; j>=0;j--)
        {
            cout << szam[j] << " ";
        }
    }
    else
    {
        cout << -1 << endl;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer1ms316 KiB
subtask20/20
2Wrong answer1ms508 KiB
3Wrong answer1ms316 KiB
4Wrong answer1ms508 KiB
5Time limit exceeded1.088s6264 KiB
6Time limit exceeded1.1s2928 KiB
7Time limit exceeded1.101s37692 KiB
8Time limit exceeded1.101s36992 KiB
9Time limit exceeded1.083s500 KiB
10Runtime error404ms262144 KiB
11Wrong answer24ms500 KiB
12Wrong answer7ms508 KiB
subtask30/25
13Wrong answer1ms316 KiB
14Wrong answer1ms544 KiB
15Wrong answer1ms316 KiB
16Time limit exceeded1.08s316 KiB
17Wrong answer1ms332 KiB
18Wrong answer76ms420 KiB
19Wrong answer1ms500 KiB
20Wrong answer1ms316 KiB
21Wrong answer1ms316 KiB
22Time limit exceeded1.1s888 KiB
23Wrong answer2ms316 KiB
24Time limit exceeded1.1s1044 KiB
25Time limit exceeded1.082s564 KiB
26Wrong answer3ms316 KiB
27Wrong answer4ms316 KiB
28Time limit exceeded1.1s4112 KiB
29Time limit exceeded1.1s1760 KiB
30Time limit exceeded1.1s5308 KiB
31Wrong answer18ms1332 KiB
32Wrong answer32ms1400 KiB
33Wrong answer10ms1332 KiB
subtask40/20
34Wrong answer1ms508 KiB
35Wrong answer1ms500 KiB
36Wrong answer1ms316 KiB
37Wrong answer1ms508 KiB
38Wrong answer137ms316 KiB
39Wrong answer1ms316 KiB
40Wrong answer7ms424 KiB
41Wrong answer1ms316 KiB
42Wrong answer1ms316 KiB
43Wrong answer1ms508 KiB
44Wrong answer138ms316 KiB
45Wrong answer1ms316 KiB
46Time limit exceeded1.1s436 KiB
47Wrong answer13ms316 KiB
48Wrong answer1ms316 KiB
49Wrong answer4ms460 KiB
50Wrong answer1ms316 KiB
51Wrong answer1ms316 KiB
52Wrong answer1ms316 KiB
53Wrong answer1ms316 KiB
54Wrong answer1ms316 KiB
55Wrong answer28ms412 KiB
56Wrong answer4ms408 KiB
57Wrong answer1ms316 KiB
58Time limit exceeded1.1s316 KiB
59Time limit exceeded1.1s332 KiB
60Wrong answer1ms316 KiB
61Wrong answer1ms316 KiB
62Wrong answer2ms316 KiB
63Wrong answer1ms316 KiB
64Wrong answer437ms316 KiB
65Wrong answer1ms316 KiB
66Time limit exceeded1.1s316 KiB
subtask50/15
67Wrong answer1ms508 KiB
68Wrong answer1ms508 KiB
69Wrong answer1ms316 KiB
70Wrong answer1ms508 KiB
71Time limit exceeded1.088s6264 KiB
72Time limit exceeded1.1s2928 KiB
73Time limit exceeded1.101s37692 KiB
74Time limit exceeded1.101s36992 KiB
75Time limit exceeded1.083s500 KiB
76Runtime error404ms262144 KiB
77Wrong answer24ms500 KiB
78Wrong answer7ms508 KiB
79Wrong answer1ms316 KiB
80Wrong answer1ms544 KiB
81Wrong answer1ms316 KiB
82Time limit exceeded1.08s316 KiB
83Wrong answer1ms332 KiB
84Wrong answer76ms420 KiB
85Wrong answer1ms500 KiB
86Wrong answer1ms316 KiB
87Wrong answer1ms316 KiB
88Time limit exceeded1.1s888 KiB
89Wrong answer2ms316 KiB
90Time limit exceeded1.1s1044 KiB
91Time limit exceeded1.082s564 KiB
92Wrong answer3ms316 KiB
93Wrong answer4ms316 KiB
94Time limit exceeded1.1s4112 KiB
95Time limit exceeded1.1s1760 KiB
96Time limit exceeded1.1s5308 KiB
97Wrong answer18ms1332 KiB
98Wrong answer32ms1400 KiB
99Wrong answer10ms1332 KiB
100Wrong answer1ms500 KiB
101Wrong answer1ms316 KiB
102Wrong answer1ms508 KiB
103Wrong answer137ms316 KiB
104Wrong answer1ms316 KiB
105Wrong answer7ms424 KiB
106Wrong answer1ms316 KiB
107Wrong answer1ms316 KiB
108Wrong answer1ms508 KiB
109Wrong answer138ms316 KiB
110Wrong answer1ms316 KiB
111Time limit exceeded1.1s436 KiB
112Wrong answer13ms316 KiB
113Wrong answer1ms316 KiB
114Wrong answer4ms460 KiB
115Wrong answer1ms316 KiB
116Wrong answer1ms316 KiB
117Wrong answer1ms316 KiB
118Wrong answer1ms316 KiB
119Wrong answer1ms316 KiB
120Wrong answer28ms412 KiB
121Wrong answer4ms408 KiB
122Wrong answer1ms316 KiB
123Time limit exceeded1.1s316 KiB
124Time limit exceeded1.1s332 KiB
125Wrong answer1ms316 KiB
126Wrong answer1ms316 KiB
127Wrong answer2ms316 KiB
128Wrong answer1ms316 KiB
129Wrong answer437ms316 KiB
130Wrong answer1ms316 KiB
131Time limit exceeded1.1s316 KiB
132Time limit exceeded1.075s1016 KiB
133Wrong answer2ms316 KiB
134Time limit exceeded1.075s1076 KiB
135Time limit exceeded1.075s820 KiB
136Time limit exceeded1.1s628 KiB
137Time limit exceeded1.072s912 KiB
138Time limit exceeded1.072s820 KiB
139Wrong answer3ms508 KiB
140Time limit exceeded1.1s6360 KiB
141Time limit exceeded1.1s15212 KiB
142Time limit exceeded1.085s15432 KiB
143Time limit exceeded1.088s46144 KiB
144Time limit exceeded1.103s38632 KiB
145Time limit exceeded1.113s157868 KiB
146Time limit exceeded1.09s83804 KiB
147Time limit exceeded1.101s217112 KiB
148Time limit exceeded1.11s179472 KiB
149Runtime error425ms262144 KiB