6402 | 2023-11-28 09:48:37 | Ghost | Legkisebb nem osztható | cpp17 | Time limit exceeded 10/100 | 3.099s | 15564 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);
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);
}
bool correct = false;
int out = 2;
while (!correct) {
node = goal;
while (node != -1) {
if (out % value[node] == 0 || (out > 2 && out % 2 == 0)) {
correct = false;
break;
}
correct = true;
node = last[node];
}
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 | 2004 KiB | ||||
3 | Accepted | 3ms | 2252 KiB | ||||
4 | Accepted | 4ms | 2436 KiB | ||||
5 | Accepted | 30ms | 2792 KiB | ||||
6 | Accepted | 70ms | 3024 KiB | ||||
7 | Accepted | 208ms | 3420 KiB | ||||
8 | Accepted | 328ms | 3496 KiB | ||||
9 | Accepted | 328ms | 3708 KiB | ||||
10 | Accepted | 330ms | 3748 KiB | ||||
11 | Accepted | 331ms | 4024 KiB | ||||
subtask3 | 5/5 | ||||||
12 | Accepted | 3ms | 3884 KiB | ||||
13 | Accepted | 3ms | 3996 KiB | ||||
14 | Accepted | 4ms | 4116 KiB | ||||
15 | Accepted | 28ms | 4036 KiB | ||||
16 | Accepted | 67ms | 4056 KiB | ||||
17 | Accepted | 202ms | 4100 KiB | ||||
18 | Accepted | 326ms | 4136 KiB | ||||
19 | Accepted | 326ms | 4148 KiB | ||||
20 | Accepted | 326ms | 4148 KiB | ||||
21 | Accepted | 324ms | 4300 KiB | ||||
subtask4 | 0/10 | ||||||
22 | Time limit exceeded | 3.062s | 4676 KiB | ||||
23 | Time limit exceeded | 3.059s | 4888 KiB | ||||
24 | Time limit exceeded | 3.082s | 9680 KiB | ||||
25 | Time limit exceeded | 3.073s | 13152 KiB | ||||
26 | Time limit exceeded | 3.065s | 14500 KiB | ||||
27 | Time limit exceeded | 3.046s | 14500 KiB | ||||
subtask5 | 0/10 | ||||||
28 | Time limit exceeded | 3.073s | 4612 KiB | ||||
29 | Time limit exceeded | 3.065s | 4856 KiB | ||||
30 | Time limit exceeded | 3.059s | 9696 KiB | ||||
31 | Time limit exceeded | 3.082s | 13376 KiB | ||||
32 | Time limit exceeded | 3.055s | 14892 KiB | ||||
33 | Time limit exceeded | 3.043s | 14788 KiB | ||||
subtask6 | 0/10 | ||||||
34 | Accepted | 328ms | 4536 KiB | ||||
35 | Time limit exceeded | 3.049s | 4852 KiB | ||||
36 | Time limit exceeded | 3.073s | 6460 KiB | ||||
37 | Time limit exceeded | 3.062s | 9716 KiB | ||||
38 | Time limit exceeded | 3.062s | 13504 KiB | ||||
39 | Time limit exceeded | 3.062s | 14672 KiB | ||||
40 | Time limit exceeded | 3.062s | 14568 KiB | ||||
41 | Time limit exceeded | 3.085s | 14860 KiB | ||||
subtask7 | 0/15 | ||||||
42 | Accepted | 324ms | 4996 KiB | ||||
43 | Time limit exceeded | 3.065s | 5128 KiB | ||||
44 | Time limit exceeded | 3.056s | 6948 KiB | ||||
45 | Time limit exceeded | 3.049s | 10336 KiB | ||||
46 | Time limit exceeded | 3.053s | 14044 KiB | ||||
47 | Time limit exceeded | 3.073s | 15392 KiB | ||||
48 | Time limit exceeded | 3.062s | 15264 KiB | ||||
49 | Time limit exceeded | 3.062s | 15372 KiB | ||||
50 | Time limit exceeded | 3.065s | 15252 KiB | ||||
51 | Time limit exceeded | 3.065s | 12744 KiB | ||||
52 | Time limit exceeded | 3.065s | 12784 KiB | ||||
53 | Time limit exceeded | 3.069s | 12812 KiB | ||||
54 | Time limit exceeded | 3.075s | 12872 KiB | ||||
55 | Time limit exceeded | 3.066s | 12848 KiB | ||||
56 | Time limit exceeded | 3.085s | 12896 KiB | ||||
subtask8 | 0/20 | ||||||
57 | Time limit exceeded | 3.078s | 5268 KiB | ||||
58 | Time limit exceeded | 3.062s | 6592 KiB | ||||
59 | Time limit exceeded | 3.042s | 8148 KiB | ||||
60 | Time limit exceeded | 3.078s | 10316 KiB | ||||
61 | Time limit exceeded | 3.065s | 14936 KiB | ||||
62 | Time limit exceeded | 3.073s | 15088 KiB | ||||
63 | Time limit exceeded | 3.051s | 15128 KiB | ||||
64 | Time limit exceeded | 3.055s | 15164 KiB | ||||
65 | Time limit exceeded | 3.049s | 15104 KiB | ||||
66 | Time limit exceeded | 3.062s | 15100 KiB | ||||
subtask9 | 0/25 | ||||||
67 | Time limit exceeded | 3.062s | 5176 KiB | ||||
68 | Time limit exceeded | 3.099s | 6648 KiB | ||||
69 | Time limit exceeded | 3.061s | 8148 KiB | ||||
70 | Time limit exceeded | 3.069s | 10560 KiB | ||||
71 | Time limit exceeded | 3.062s | 15040 KiB | ||||
72 | Time limit exceeded | 3.069s | 15396 KiB | ||||
73 | Time limit exceeded | 3.062s | 15428 KiB | ||||
74 | Time limit exceeded | 3.082s | 15480 KiB | ||||
75 | Time limit exceeded | 3.053s | 15472 KiB | ||||
76 | Time limit exceeded | 3.069s | 15288 KiB | ||||
77 | Time limit exceeded | 3.065s | 15172 KiB | ||||
78 | Time limit exceeded | 3.053s | 15364 KiB | ||||
79 | Time limit exceeded | 3.065s | 15288 KiB | ||||
80 | Time limit exceeded | 3.068s | 15532 KiB | ||||
81 | Time limit exceeded | 3.053s | 15564 KiB | ||||
82 | Time limit exceeded | 3.042s | 15092 KiB | ||||
83 | Time limit exceeded | 3.062s | 15492 KiB |