6398 | 2023-11-27 14:14:48 | Ghost | Legkisebb nem osztható | cpp17 | Runtime error 0/100 | 916ms | 524892 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;
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Runtime error | 814ms | 524892 KiB | ||||
subtask2 | 0/5 | ||||||
2 | Runtime error | 841ms | 524612 KiB | ||||
3 | Runtime error | 809ms | 524368 KiB | ||||
4 | Runtime error | 726ms | 524148 KiB | ||||
5 | Runtime error | 737ms | 523920 KiB | ||||
6 | Runtime error | 735ms | 523672 KiB | ||||
7 | Runtime error | 726ms | 523656 KiB | ||||
8 | Runtime error | 771ms | 523644 KiB | ||||
9 | Runtime error | 777ms | 523396 KiB | ||||
10 | Runtime error | 767ms | 523152 KiB | ||||
11 | Runtime error | 768ms | 522900 KiB | ||||
subtask3 | 0/5 | ||||||
12 | Runtime error | 720ms | 522680 KiB | ||||
13 | Runtime error | 591ms | 522612 KiB | ||||
14 | Runtime error | 638ms | 522620 KiB | ||||
15 | Runtime error | 597ms | 522508 KiB | ||||
16 | Runtime error | 505ms | 522500 KiB | ||||
17 | Runtime error | 592ms | 522496 KiB | ||||
18 | Runtime error | 547ms | 522476 KiB | ||||
19 | Runtime error | 564ms | 522336 KiB | ||||
20 | Runtime error | 603ms | 522088 KiB | ||||
21 | Runtime error | 568ms | 521840 KiB | ||||
subtask4 | 0/10 | ||||||
22 | Runtime error | 727ms | 521852 KiB | ||||
23 | Runtime error | 773ms | 521844 KiB | ||||
24 | Runtime error | 768ms | 521848 KiB | ||||
25 | Runtime error | 836ms | 521844 KiB | ||||
26 | Runtime error | 852ms | 521848 KiB | ||||
27 | Runtime error | 847ms | 521856 KiB | ||||
subtask5 | 0/10 | ||||||
28 | Runtime error | 607ms | 521764 KiB | ||||
29 | Runtime error | 597ms | 521520 KiB | ||||
30 | Runtime error | 669ms | 521516 KiB | ||||
31 | Runtime error | 721ms | 521496 KiB | ||||
32 | Runtime error | 731ms | 521524 KiB | ||||
33 | Runtime error | 728ms | 521512 KiB | ||||
subtask6 | 0/10 | ||||||
34 | Runtime error | 764ms | 521520 KiB | ||||
35 | Runtime error | 728ms | 521512 KiB | ||||
36 | Runtime error | 787ms | 521516 KiB | ||||
37 | Runtime error | 816ms | 521492 KiB | ||||
38 | Runtime error | 808ms | 521520 KiB | ||||
39 | Runtime error | 862ms | 521280 KiB | ||||
40 | Runtime error | 864ms | 521272 KiB | ||||
41 | Runtime error | 867ms | 521268 KiB | ||||
subtask7 | 0/15 | ||||||
42 | Runtime error | 560ms | 521272 KiB | ||||
43 | Runtime error | 578ms | 521264 KiB | ||||
44 | Runtime error | 670ms | 521256 KiB | ||||
45 | Runtime error | 707ms | 521248 KiB | ||||
46 | Runtime error | 754ms | 521268 KiB | ||||
47 | Runtime error | 694ms | 521272 KiB | ||||
48 | Runtime error | 731ms | 521268 KiB | ||||
49 | Runtime error | 717ms | 521232 KiB | ||||
50 | Runtime error | 707ms | 521236 KiB | ||||
51 | Runtime error | 859ms | 521232 KiB | ||||
52 | Runtime error | 786ms | 521228 KiB | ||||
53 | Runtime error | 843ms | 521208 KiB | ||||
54 | Runtime error | 902ms | 521192 KiB | ||||
55 | Runtime error | 787ms | 521212 KiB | ||||
56 | Runtime error | 744ms | 521208 KiB | ||||
subtask8 | 0/20 | ||||||
57 | Runtime error | 726ms | 521196 KiB | ||||
58 | Runtime error | 783ms | 521208 KiB | ||||
59 | Runtime error | 750ms | 521208 KiB | ||||
60 | Runtime error | 764ms | 521208 KiB | ||||
61 | Runtime error | 825ms | 521064 KiB | ||||
62 | Runtime error | 861ms | 521064 KiB | ||||
63 | Runtime error | 810ms | 521060 KiB | ||||
64 | Runtime error | 864ms | 521056 KiB | ||||
65 | Runtime error | 862ms | 521040 KiB | ||||
66 | Runtime error | 859ms | 521040 KiB | ||||
subtask9 | 0/25 | ||||||
67 | Runtime error | 635ms | 521040 KiB | ||||
68 | Runtime error | 607ms | 521040 KiB | ||||
69 | Runtime error | 689ms | 521048 KiB | ||||
70 | Runtime error | 653ms | 521044 KiB | ||||
71 | Runtime error | 771ms | 521044 KiB | ||||
72 | Runtime error | 740ms | 521040 KiB | ||||
73 | Runtime error | 709ms | 521036 KiB | ||||
74 | Runtime error | 709ms | 521044 KiB | ||||
75 | Runtime error | 740ms | 521040 KiB | ||||
76 | Runtime error | 754ms | 521048 KiB | ||||
77 | Runtime error | 705ms | 521040 KiB | ||||
78 | Runtime error | 736ms | 521036 KiB | ||||
79 | Runtime error | 759ms | 521008 KiB | ||||
80 | Runtime error | 446ms | 521008 KiB | ||||
81 | Runtime error | 398ms | 520996 KiB | ||||
82 | Runtime error | 419ms | 520984 KiB | ||||
83 | Runtime error | 916ms | 520988 KiB |