6399 | 2023-11-27 18:29:02 | Ghost | Legkisebb nem osztható | cpp17 | Time limit exceeded 10/100 | 3.086s | 100328 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++) {
if (!been.count(map[node][j])) {
steps.push(map[node][j]);
last[map[node][j]] = node;
}
}
been.insert(node);
}
outV.clear();
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) {
correct = false;
break;
}
correct = true;
}
if (correct) {
break;
}
out++;
}
cout << out << "\n";
}
}
//9
//7 25 8 4 1000000 6 11 3 2
//5 7
//5 1
//5 6
//7 3
//1 2
//1 4
//6 8
//2 9
//3
//8 9
//3 8
//4 9
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1812 KiB | ||||
subtask2 | 5/5 | ||||||
2 | Accepted | 3ms | 2064 KiB | ||||
3 | Accepted | 3ms | 2212 KiB | ||||
4 | Accepted | 4ms | 2308 KiB | ||||
5 | Accepted | 30ms | 2396 KiB | ||||
6 | Accepted | 71ms | 2760 KiB | ||||
7 | Accepted | 209ms | 3164 KiB | ||||
8 | Accepted | 330ms | 3328 KiB | ||||
9 | Accepted | 331ms | 3440 KiB | ||||
10 | Accepted | 331ms | 3592 KiB | ||||
11 | Accepted | 333ms | 3848 KiB | ||||
subtask3 | 5/5 | ||||||
12 | Accepted | 3ms | 3728 KiB | ||||
13 | Accepted | 3ms | 3780 KiB | ||||
14 | Accepted | 4ms | 3792 KiB | ||||
15 | Accepted | 28ms | 3892 KiB | ||||
16 | Accepted | 68ms | 4172 KiB | ||||
17 | Accepted | 202ms | 4216 KiB | ||||
18 | Accepted | 326ms | 4452 KiB | ||||
19 | Accepted | 326ms | 4532 KiB | ||||
20 | Accepted | 324ms | 4520 KiB | ||||
21 | Accepted | 324ms | 4776 KiB | ||||
subtask4 | 0/10 | ||||||
22 | Time limit exceeded | 3.081s | 5336 KiB | ||||
23 | Time limit exceeded | 3.053s | 6072 KiB | ||||
24 | Time limit exceeded | 3.082s | 11944 KiB | ||||
25 | Time limit exceeded | 3.082s | 17120 KiB | ||||
26 | Time limit exceeded | 3.065s | 20064 KiB | ||||
27 | Time limit exceeded | 3.059s | 21612 KiB | ||||
subtask5 | 0/10 | ||||||
28 | Time limit exceeded | 3.075s | 11624 KiB | ||||
29 | Time limit exceeded | 3.078s | 12328 KiB | ||||
30 | Time limit exceeded | 3.053s | 18000 KiB | ||||
31 | Time limit exceeded | 3.058s | 23072 KiB | ||||
32 | Time limit exceeded | 3.062s | 25824 KiB | ||||
33 | Time limit exceeded | 3.075s | 27204 KiB | ||||
subtask6 | 0/10 | ||||||
34 | Accepted | 330ms | 17208 KiB | ||||
35 | Time limit exceeded | 3.058s | 17696 KiB | ||||
36 | Time limit exceeded | 3.072s | 20076 KiB | ||||
37 | Time limit exceeded | 3.038s | 24768 KiB | ||||
38 | Time limit exceeded | 3.069s | 30456 KiB | ||||
39 | Time limit exceeded | 3.065s | 33804 KiB | ||||
40 | Time limit exceeded | 3.059s | 35748 KiB | ||||
41 | Time limit exceeded | 3.078s | 37568 KiB | ||||
subtask7 | 0/15 | ||||||
42 | Accepted | 328ms | 27048 KiB | ||||
43 | Time limit exceeded | 3.046s | 27448 KiB | ||||
44 | Time limit exceeded | 3.049s | 29760 KiB | ||||
45 | Time limit exceeded | 3.058s | 34228 KiB | ||||
46 | Time limit exceeded | 3.062s | 39728 KiB | ||||
47 | Time limit exceeded | 3.075s | 42840 KiB | ||||
48 | Time limit exceeded | 3.066s | 45148 KiB | ||||
49 | Time limit exceeded | 3.062s | 47380 KiB | ||||
50 | Time limit exceeded | 3.062s | 49168 KiB | ||||
51 | Time limit exceeded | 3.066s | 48648 KiB | ||||
52 | Time limit exceeded | 3.066s | 50036 KiB | ||||
53 | Time limit exceeded | 3.066s | 51892 KiB | ||||
54 | Time limit exceeded | 3.071s | 53584 KiB | ||||
55 | Time limit exceeded | 3.058s | 54944 KiB | ||||
56 | Time limit exceeded | 3.059s | 56496 KiB | ||||
subtask8 | 0/20 | ||||||
57 | Time limit exceeded | 3.075s | 49252 KiB | ||||
58 | Time limit exceeded | 3.046s | 51412 KiB | ||||
59 | Time limit exceeded | 3.062s | 53548 KiB | ||||
60 | Time limit exceeded | 3.069s | 57032 KiB | ||||
61 | Time limit exceeded | 3.086s | 63924 KiB | ||||
62 | Time limit exceeded | 3.066s | 66164 KiB | ||||
63 | Time limit exceeded | 3.071s | 67764 KiB | ||||
64 | Time limit exceeded | 3.051s | 69524 KiB | ||||
65 | Time limit exceeded | 3.035s | 71620 KiB | ||||
66 | Time limit exceeded | 3.078s | 73704 KiB | ||||
subtask9 | 0/25 | ||||||
67 | Time limit exceeded | 3.045s | 63584 KiB | ||||
68 | Time limit exceeded | 3.056s | 65400 KiB | ||||
69 | Time limit exceeded | 3.072s | 67668 KiB | ||||
70 | Time limit exceeded | 3.061s | 71040 KiB | ||||
71 | Time limit exceeded | 3.042s | 77608 KiB | ||||
72 | Time limit exceeded | 3.059s | 79760 KiB | ||||
73 | Time limit exceeded | 3.075s | 81564 KiB | ||||
74 | Time limit exceeded | 3.059s | 83372 KiB | ||||
75 | Time limit exceeded | 3.066s | 85152 KiB | ||||
76 | Time limit exceeded | 3.075s | 87120 KiB | ||||
77 | Time limit exceeded | 3.046s | 88768 KiB | ||||
78 | Time limit exceeded | 3.071s | 90388 KiB | ||||
79 | Time limit exceeded | 3.059s | 92196 KiB | ||||
80 | Time limit exceeded | 3.059s | 94428 KiB | ||||
81 | Time limit exceeded | 3.042s | 96284 KiB | ||||
82 | Time limit exceeded | 3.062s | 98468 KiB | ||||
83 | Time limit exceeded | 3.082s | 100328 KiB |