6406 | 2023-11-28 10:02:05 | Ghost | Legkisebb nem osztható | cpp17 | Wrong answer 0/100 | 3.084s | 15784 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]) {
if (out % value[node] == 0 || (out > 2 && out % 2 == 0)) {
correct = false;
break;
}
correct = true;
node = last[node];
}
else {
break;
}
}
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 | Wrong answer | 3ms | 1944 KiB | ||||
subtask2 | 0/5 | ||||||
2 | Wrong answer | 3ms | 2112 KiB | ||||
3 | Wrong answer | 3ms | 2332 KiB | ||||
4 | Wrong answer | 6ms | 2384 KiB | ||||
5 | Wrong answer | 731ms | 2728 KiB | ||||
6 | Wrong answer | 842ms | 2828 KiB | ||||
7 | Wrong answer | 906ms | 3056 KiB | ||||
8 | Wrong answer | 1.083s | 3156 KiB | ||||
9 | Wrong answer | 1.024s | 3408 KiB | ||||
10 | Wrong answer | 330ms | 3620 KiB | ||||
11 | Wrong answer | 328ms | 3888 KiB | ||||
subtask3 | 0/5 | ||||||
12 | Wrong answer | 3ms | 3680 KiB | ||||
13 | Wrong answer | 3ms | 3684 KiB | ||||
14 | Wrong answer | 4ms | 3700 KiB | ||||
15 | Wrong answer | 814ms | 3924 KiB | ||||
16 | Wrong answer | 778ms | 4260 KiB | ||||
17 | Wrong answer | 939ms | 4172 KiB | ||||
18 | Wrong answer | 1.046s | 4116 KiB | ||||
19 | Wrong answer | 1.027s | 4372 KiB | ||||
20 | Wrong answer | 326ms | 4380 KiB | ||||
21 | Wrong answer | 326ms | 4332 KiB | ||||
subtask4 | 0/10 | ||||||
22 | Time limit exceeded | 3.073s | 4604 KiB | ||||
23 | Time limit exceeded | 3.046s | 4708 KiB | ||||
24 | Time limit exceeded | 3.066s | 9508 KiB | ||||
25 | Time limit exceeded | 3.062s | 13132 KiB | ||||
26 | Time limit exceeded | 3.059s | 14384 KiB | ||||
27 | Time limit exceeded | 3.053s | 14452 KiB | ||||
subtask5 | 0/10 | ||||||
28 | Time limit exceeded | 3.078s | 4596 KiB | ||||
29 | Time limit exceeded | 3.035s | 4964 KiB | ||||
30 | Time limit exceeded | 3.062s | 9900 KiB | ||||
31 | Time limit exceeded | 3.049s | 13700 KiB | ||||
32 | Time limit exceeded | 3.066s | 14804 KiB | ||||
33 | Time limit exceeded | 3.068s | 14988 KiB | ||||
subtask6 | 0/10 | ||||||
34 | Wrong answer | 330ms | 5084 KiB | ||||
35 | Time limit exceeded | 3.062s | 5056 KiB | ||||
36 | Time limit exceeded | 3.073s | 6576 KiB | ||||
37 | Time limit exceeded | 3.049s | 9944 KiB | ||||
38 | Time limit exceeded | 3.073s | 13796 KiB | ||||
39 | Time limit exceeded | 3.079s | 14964 KiB | ||||
40 | Time limit exceeded | 3.062s | 15120 KiB | ||||
41 | Time limit exceeded | 3.078s | 15076 KiB | ||||
subtask7 | 0/15 | ||||||
42 | Wrong answer | 328ms | 5048 KiB | ||||
43 | Time limit exceeded | 3.026s | 5140 KiB | ||||
44 | Time limit exceeded | 3.039s | 6824 KiB | ||||
45 | Time limit exceeded | 3.069s | 10256 KiB | ||||
46 | Time limit exceeded | 3.072s | 14132 KiB | ||||
47 | Time limit exceeded | 3.084s | 15292 KiB | ||||
48 | Time limit exceeded | 3.075s | 15252 KiB | ||||
49 | Time limit exceeded | 3.075s | 15212 KiB | ||||
50 | Time limit exceeded | 3.073s | 15372 KiB | ||||
51 | Time limit exceeded | 3.058s | 12688 KiB | ||||
52 | Time limit exceeded | 3.072s | 12784 KiB | ||||
53 | Time limit exceeded | 3.062s | 12804 KiB | ||||
54 | Time limit exceeded | 3.058s | 12776 KiB | ||||
55 | Time limit exceeded | 3.079s | 12704 KiB | ||||
56 | Time limit exceeded | 3.062s | 12956 KiB | ||||
subtask8 | 0/20 | ||||||
57 | Time limit exceeded | 3.073s | 5376 KiB | ||||
58 | Time limit exceeded | 3.078s | 6640 KiB | ||||
59 | Time limit exceeded | 3.082s | 8156 KiB | ||||
60 | Time limit exceeded | 3.069s | 10452 KiB | ||||
61 | Time limit exceeded | 3.059s | 14848 KiB | ||||
62 | Time limit exceeded | 3.079s | 14960 KiB | ||||
63 | Time limit exceeded | 3.079s | 15012 KiB | ||||
64 | Time limit exceeded | 3.066s | 15060 KiB | ||||
65 | Time limit exceeded | 3.072s | 15032 KiB | ||||
66 | Time limit exceeded | 3.071s | 15188 KiB | ||||
subtask9 | 0/25 | ||||||
67 | Time limit exceeded | 3.049s | 5236 KiB | ||||
68 | Time limit exceeded | 3.075s | 6640 KiB | ||||
69 | Time limit exceeded | 3.046s | 7968 KiB | ||||
70 | Time limit exceeded | 3.078s | 10528 KiB | ||||
71 | Time limit exceeded | 3.066s | 15248 KiB | ||||
72 | Time limit exceeded | 3.082s | 15340 KiB | ||||
73 | Time limit exceeded | 3.078s | 15392 KiB | ||||
74 | Time limit exceeded | 3.059s | 15336 KiB | ||||
75 | Time limit exceeded | 3.062s | 15276 KiB | ||||
76 | Time limit exceeded | 3.069s | 15416 KiB | ||||
77 | Time limit exceeded | 3.071s | 15700 KiB | ||||
78 | Time limit exceeded | 3.075s | 15488 KiB | ||||
79 | Time limit exceeded | 3.082s | 15532 KiB | ||||
80 | Time limit exceeded | 3.071s | 15784 KiB | ||||
81 | Time limit exceeded | 3.058s | 15608 KiB | ||||
82 | Time limit exceeded | 3.073s | 15208 KiB | ||||
83 | Time limit exceeded | 3.075s | 15476 KiB |