63982023-11-27 14:14:48GhostLegkisebb nem oszthatócpp17Runtime error 0/100916ms524892 KiB
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>

using namespace std;

int main()
{
    int n, temp1, temp2, i;
    cin >> n;

    vector<int> value(n);
    for (i = 0; i < n; i++) {
        cin >> value[i];
    }

    vector<vector<int>> map(n);
    for (i = 0; i < (n - 1); i++) {
        cin >> temp1 >> temp2;
        temp1--; temp2--;
        map[temp1].push_back(temp2);
        map[temp2].push_back(temp1);
    }

    int k, goal, start, j;
    cin >> k;
    set<int> been;
    queue<int> steps;
    vector<int> last(n), outV;
    for (i = 0; i < k; i++) {
        cin >> start >> goal;
        start--; goal--;
        last[start] = -1;

        been.clear();
        been.insert(start);
        steps.push(start);

        int node;
        while (steps.size() > 0) {
            node = steps.front();
            steps.pop();

            for (j = 0; j < map[node].size(); j++) {
                steps.push(map[node][j]);
                last[map[node][j]] = node;
            }
        }

        node = goal;
        while (node != -1) {
            outV.push_back(value[node]);
            node = last[node];
        }

        bool correct = false;
        int out = 2;
        while (!correct) {
            for (j = 0; j < outV.size(); j++) {
                if (out % outV[j] == 0) {
                    continue;
                }
                correct = true;
                break;
            }
            out++;
        }

        cout << out;
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Runtime error814ms524892 KiB
subtask20/5
2Runtime error841ms524612 KiB
3Runtime error809ms524368 KiB
4Runtime error726ms524148 KiB
5Runtime error737ms523920 KiB
6Runtime error735ms523672 KiB
7Runtime error726ms523656 KiB
8Runtime error771ms523644 KiB
9Runtime error777ms523396 KiB
10Runtime error767ms523152 KiB
11Runtime error768ms522900 KiB
subtask30/5
12Runtime error720ms522680 KiB
13Runtime error591ms522612 KiB
14Runtime error638ms522620 KiB
15Runtime error597ms522508 KiB
16Runtime error505ms522500 KiB
17Runtime error592ms522496 KiB
18Runtime error547ms522476 KiB
19Runtime error564ms522336 KiB
20Runtime error603ms522088 KiB
21Runtime error568ms521840 KiB
subtask40/10
22Runtime error727ms521852 KiB
23Runtime error773ms521844 KiB
24Runtime error768ms521848 KiB
25Runtime error836ms521844 KiB
26Runtime error852ms521848 KiB
27Runtime error847ms521856 KiB
subtask50/10
28Runtime error607ms521764 KiB
29Runtime error597ms521520 KiB
30Runtime error669ms521516 KiB
31Runtime error721ms521496 KiB
32Runtime error731ms521524 KiB
33Runtime error728ms521512 KiB
subtask60/10
34Runtime error764ms521520 KiB
35Runtime error728ms521512 KiB
36Runtime error787ms521516 KiB
37Runtime error816ms521492 KiB
38Runtime error808ms521520 KiB
39Runtime error862ms521280 KiB
40Runtime error864ms521272 KiB
41Runtime error867ms521268 KiB
subtask70/15
42Runtime error560ms521272 KiB
43Runtime error578ms521264 KiB
44Runtime error670ms521256 KiB
45Runtime error707ms521248 KiB
46Runtime error754ms521268 KiB
47Runtime error694ms521272 KiB
48Runtime error731ms521268 KiB
49Runtime error717ms521232 KiB
50Runtime error707ms521236 KiB
51Runtime error859ms521232 KiB
52Runtime error786ms521228 KiB
53Runtime error843ms521208 KiB
54Runtime error902ms521192 KiB
55Runtime error787ms521212 KiB
56Runtime error744ms521208 KiB
subtask80/20
57Runtime error726ms521196 KiB
58Runtime error783ms521208 KiB
59Runtime error750ms521208 KiB
60Runtime error764ms521208 KiB
61Runtime error825ms521064 KiB
62Runtime error861ms521064 KiB
63Runtime error810ms521060 KiB
64Runtime error864ms521056 KiB
65Runtime error862ms521040 KiB
66Runtime error859ms521040 KiB
subtask90/25
67Runtime error635ms521040 KiB
68Runtime error607ms521040 KiB
69Runtime error689ms521048 KiB
70Runtime error653ms521044 KiB
71Runtime error771ms521044 KiB
72Runtime error740ms521040 KiB
73Runtime error709ms521036 KiB
74Runtime error709ms521044 KiB
75Runtime error740ms521040 KiB
76Runtime error754ms521048 KiB
77Runtime error705ms521040 KiB
78Runtime error736ms521036 KiB
79Runtime error759ms521008 KiB
80Runtime error446ms521008 KiB
81Runtime error398ms520996 KiB
82Runtime error419ms520984 KiB
83Runtime error916ms520988 KiB