6407 | 2023-11-28 10:06:40 | Ghost | Legkisebb nem osztható | cpp17 | Wrong answer 0/100 | 3.101s | 15720 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 {
node = last[node];
continue;
}
}
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 | 1812 KiB | ||||
subtask2 | 0/5 | ||||||
2 | Accepted | 3ms | 2004 KiB | ||||
3 | Wrong answer | 4ms | 2244 KiB | ||||
4 | Wrong answer | 6ms | 2248 KiB | ||||
5 | Wrong answer | 1.264s | 2248 KiB | ||||
6 | Wrong answer | 1.975s | 2260 KiB | ||||
7 | Time limit exceeded | 3.078s | 1864 KiB | ||||
8 | Time limit exceeded | 3.053s | 2876 KiB | ||||
9 | Time limit exceeded | 3.017s | 2996 KiB | ||||
10 | Wrong answer | 331ms | 3284 KiB | ||||
11 | Wrong answer | 333ms | 3240 KiB | ||||
subtask3 | 0/5 | ||||||
12 | Wrong answer | 3ms | 3220 KiB | ||||
13 | Wrong answer | 3ms | 3480 KiB | ||||
14 | Wrong answer | 4ms | 3656 KiB | ||||
15 | Wrong answer | 971ms | 3756 KiB | ||||
16 | Wrong answer | 1.103s | 3984 KiB | ||||
17 | Wrong answer | 1.238s | 4004 KiB | ||||
18 | Wrong answer | 1.299s | 4044 KiB | ||||
19 | Wrong answer | 894ms | 4176 KiB | ||||
20 | Wrong answer | 326ms | 4240 KiB | ||||
21 | Wrong answer | 324ms | 4208 KiB | ||||
subtask4 | 0/10 | ||||||
22 | Time limit exceeded | 3.078s | 4392 KiB | ||||
23 | Time limit exceeded | 3.059s | 4892 KiB | ||||
24 | Time limit exceeded | 3.078s | 9760 KiB | ||||
25 | Time limit exceeded | 3.03s | 13584 KiB | ||||
26 | Time limit exceeded | 3.082s | 14736 KiB | ||||
27 | Time limit exceeded | 3.071s | 14900 KiB | ||||
subtask5 | 0/10 | ||||||
28 | Time limit exceeded | 3.062s | 4932 KiB | ||||
29 | Time limit exceeded | 3.062s | 5060 KiB | ||||
30 | Time limit exceeded | 3.069s | 9956 KiB | ||||
31 | Time limit exceeded | 3.072s | 13872 KiB | ||||
32 | Time limit exceeded | 3.066s | 15060 KiB | ||||
33 | Time limit exceeded | 3.072s | 14944 KiB | ||||
subtask6 | 0/10 | ||||||
34 | Wrong answer | 333ms | 4764 KiB | ||||
35 | Time limit exceeded | 3.062s | 5092 KiB | ||||
36 | Time limit exceeded | 3.076s | 6736 KiB | ||||
37 | Time limit exceeded | 3.062s | 10204 KiB | ||||
38 | Time limit exceeded | 3.065s | 13848 KiB | ||||
39 | Time limit exceeded | 3.063s | 15068 KiB | ||||
40 | Time limit exceeded | 3.059s | 15156 KiB | ||||
41 | Time limit exceeded | 3.059s | 15048 KiB | ||||
subtask7 | 0/15 | ||||||
42 | Wrong answer | 328ms | 5180 KiB | ||||
43 | Time limit exceeded | 3.078s | 5252 KiB | ||||
44 | Time limit exceeded | 3.062s | 6852 KiB | ||||
45 | Time limit exceeded | 3.051s | 10360 KiB | ||||
46 | Time limit exceeded | 3.062s | 14276 KiB | ||||
47 | Time limit exceeded | 3.078s | 15544 KiB | ||||
48 | Time limit exceeded | 3.059s | 15344 KiB | ||||
49 | Time limit exceeded | 3.055s | 15360 KiB | ||||
50 | Time limit exceeded | 3.058s | 15360 KiB | ||||
51 | Time limit exceeded | 3.043s | 12804 KiB | ||||
52 | Time limit exceeded | 3.066s | 12816 KiB | ||||
53 | Time limit exceeded | 3.069s | 13080 KiB | ||||
54 | Time limit exceeded | 3.058s | 12812 KiB | ||||
55 | Time limit exceeded | 3.058s | 12740 KiB | ||||
56 | Time limit exceeded | 3.075s | 12912 KiB | ||||
subtask8 | 0/20 | ||||||
57 | Time limit exceeded | 3.062s | 5292 KiB | ||||
58 | Time limit exceeded | 3.055s | 6728 KiB | ||||
59 | Time limit exceeded | 3.046s | 8148 KiB | ||||
60 | Time limit exceeded | 3.065s | 10540 KiB | ||||
61 | Time limit exceeded | 3.084s | 15192 KiB | ||||
62 | Time limit exceeded | 3.058s | 15288 KiB | ||||
63 | Time limit exceeded | 3.059s | 15256 KiB | ||||
64 | Time limit exceeded | 3.101s | 15324 KiB | ||||
65 | Time limit exceeded | 3.062s | 15256 KiB | ||||
66 | Time limit exceeded | 3.069s | 15320 KiB | ||||
subtask9 | 0/25 | ||||||
67 | Time limit exceeded | 3.065s | 5460 KiB | ||||
68 | Time limit exceeded | 3.073s | 6888 KiB | ||||
69 | Time limit exceeded | 3.062s | 8344 KiB | ||||
70 | Time limit exceeded | 3.065s | 10732 KiB | ||||
71 | Time limit exceeded | 3.058s | 15320 KiB | ||||
72 | Time limit exceeded | 3.073s | 15612 KiB | ||||
73 | Time limit exceeded | 3.065s | 15700 KiB | ||||
74 | Time limit exceeded | 3.065s | 15640 KiB | ||||
75 | Time limit exceeded | 3.059s | 15516 KiB | ||||
76 | Time limit exceeded | 3.071s | 15520 KiB | ||||
77 | Time limit exceeded | 3.073s | 15692 KiB | ||||
78 | Time limit exceeded | 3.062s | 15584 KiB | ||||
79 | Time limit exceeded | 3.073s | 15588 KiB | ||||
80 | Time limit exceeded | 3.068s | 15720 KiB | ||||
81 | Time limit exceeded | 3.068s | 15652 KiB | ||||
82 | Time limit exceeded | 3.059s | 15264 KiB | ||||
83 | Time limit exceeded | 3.082s | 15512 KiB |