# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
557582 |
2022-05-05T14:05:17 Z |
DanShaders |
Jail (JOI22_jail) |
C++17 |
|
5000 ms |
265632 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
namespace x = __gnu_pbds;
template <typename T>
using ordered_set = x::tree<T, x::null_type, less<T>, x::rb_tree_tag, x::tree_order_statistics_node_update>;
template <typename T>
using normal_queue = priority_queue<T, vector<T>, greater<>>;
#define all(x) begin(x), end(x)
#define sz(x) ((int) (x).size())
#define x first
#define y second
using ll = long long;
using ld = long double;
const int N = 1.3e5;
int s[N], t[N];
vector<int> g[N], paths[N], g2[N];
char used[N];
vector<int> path;
bool dfs_cycle(int u) {
if (used[u] == 1) {
return false;
}
used[u] = 1;
for (int v : g2[u]) {
if (used[v] != 2 && !dfs_cycle(v)) {
return false;
}
}
used[u] = 2;
return true;
}
bool dfs(int u, int w, int p = -1) {
path.push_back(u);
if (u == w) {
return true;
}
for (int v : g[u]) {
if (v != p && dfs(v, w, u)) {
return true;
}
}
path.pop_back();
return false;
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int testcases;
cin >> testcases;
while (testcases--) {
int n, m;
cin >> n;
for (int i = 0; i < n; ++i) {
g[i].clear();
g2[i].clear();
paths[i].clear();
}
for (int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v;
g[--u].push_back(--v);
g[v].push_back(u);
}
cin >> m;
for (int i = 0; i < m; ++i) {
cin >> s[i] >> t[i];
--s[i], --t[i];
path.clear();
dfs(s[i], t[i]);
for (int u : path) {
paths[u].push_back(i);
}
}
for (int i = 0; i < m; ++i) {
for (int j : paths[s[i]]) {
if (i != j) {
// cout << j << " -> " << i << endl;
g2[j].push_back(i);
}
}
for (int j : paths[t[i]]) {
// cout << i << " -> " << j << endl;
if (i != j) {
g2[i].push_back(j);
}
}
}
fill(used, used + m, 0);
bool flag = true;
for (int i = 0; i < m; ++i) {
if (!used[i]) {
flag &= dfs_cycle(i);
}
}
cout << (flag ? "Yes\n" : "No\n");
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9428 KB |
Output is correct |
2 |
Correct |
5 ms |
9436 KB |
Output is correct |
3 |
Correct |
5 ms |
9428 KB |
Output is correct |
4 |
Correct |
14 ms |
9496 KB |
Output is correct |
5 |
Correct |
23 ms |
9428 KB |
Output is correct |
6 |
Correct |
6 ms |
9556 KB |
Output is correct |
7 |
Correct |
5 ms |
9428 KB |
Output is correct |
8 |
Correct |
9 ms |
9684 KB |
Output is correct |
9 |
Correct |
377 ms |
24876 KB |
Output is correct |
10 |
Correct |
2222 ms |
265356 KB |
Output is correct |
11 |
Correct |
10 ms |
9644 KB |
Output is correct |
12 |
Correct |
63 ms |
10520 KB |
Output is correct |
13 |
Execution timed out |
5022 ms |
28400 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9484 KB |
Output is correct |
2 |
Correct |
6 ms |
9460 KB |
Output is correct |
3 |
Correct |
9 ms |
9428 KB |
Output is correct |
4 |
Correct |
6 ms |
9492 KB |
Output is correct |
5 |
Correct |
6 ms |
9428 KB |
Output is correct |
6 |
Correct |
6 ms |
9540 KB |
Output is correct |
7 |
Correct |
9 ms |
9480 KB |
Output is correct |
8 |
Correct |
6 ms |
9428 KB |
Output is correct |
9 |
Correct |
7 ms |
9428 KB |
Output is correct |
10 |
Correct |
6 ms |
9536 KB |
Output is correct |
11 |
Correct |
7 ms |
9512 KB |
Output is correct |
12 |
Correct |
6 ms |
9500 KB |
Output is correct |
13 |
Correct |
8 ms |
9428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9484 KB |
Output is correct |
2 |
Correct |
6 ms |
9460 KB |
Output is correct |
3 |
Correct |
9 ms |
9428 KB |
Output is correct |
4 |
Correct |
6 ms |
9492 KB |
Output is correct |
5 |
Correct |
6 ms |
9428 KB |
Output is correct |
6 |
Correct |
6 ms |
9540 KB |
Output is correct |
7 |
Correct |
9 ms |
9480 KB |
Output is correct |
8 |
Correct |
6 ms |
9428 KB |
Output is correct |
9 |
Correct |
7 ms |
9428 KB |
Output is correct |
10 |
Correct |
6 ms |
9536 KB |
Output is correct |
11 |
Correct |
7 ms |
9512 KB |
Output is correct |
12 |
Correct |
6 ms |
9500 KB |
Output is correct |
13 |
Correct |
8 ms |
9428 KB |
Output is correct |
14 |
Correct |
5 ms |
9428 KB |
Output is correct |
15 |
Correct |
5 ms |
9484 KB |
Output is correct |
16 |
Correct |
6 ms |
9556 KB |
Output is correct |
17 |
Correct |
8 ms |
9460 KB |
Output is correct |
18 |
Correct |
6 ms |
9496 KB |
Output is correct |
19 |
Correct |
6 ms |
9488 KB |
Output is correct |
20 |
Correct |
6 ms |
9428 KB |
Output is correct |
21 |
Correct |
6 ms |
9504 KB |
Output is correct |
22 |
Correct |
6 ms |
9496 KB |
Output is correct |
23 |
Correct |
6 ms |
9428 KB |
Output is correct |
24 |
Correct |
6 ms |
9400 KB |
Output is correct |
25 |
Correct |
7 ms |
9428 KB |
Output is correct |
26 |
Correct |
6 ms |
9488 KB |
Output is correct |
27 |
Correct |
7 ms |
9436 KB |
Output is correct |
28 |
Correct |
6 ms |
9428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9484 KB |
Output is correct |
2 |
Correct |
6 ms |
9460 KB |
Output is correct |
3 |
Correct |
9 ms |
9428 KB |
Output is correct |
4 |
Correct |
6 ms |
9492 KB |
Output is correct |
5 |
Correct |
6 ms |
9428 KB |
Output is correct |
6 |
Correct |
6 ms |
9540 KB |
Output is correct |
7 |
Correct |
9 ms |
9480 KB |
Output is correct |
8 |
Correct |
6 ms |
9428 KB |
Output is correct |
9 |
Correct |
7 ms |
9428 KB |
Output is correct |
10 |
Correct |
6 ms |
9536 KB |
Output is correct |
11 |
Correct |
7 ms |
9512 KB |
Output is correct |
12 |
Correct |
6 ms |
9500 KB |
Output is correct |
13 |
Correct |
8 ms |
9428 KB |
Output is correct |
14 |
Correct |
5 ms |
9428 KB |
Output is correct |
15 |
Correct |
5 ms |
9484 KB |
Output is correct |
16 |
Correct |
6 ms |
9556 KB |
Output is correct |
17 |
Correct |
8 ms |
9460 KB |
Output is correct |
18 |
Correct |
6 ms |
9496 KB |
Output is correct |
19 |
Correct |
6 ms |
9488 KB |
Output is correct |
20 |
Correct |
6 ms |
9428 KB |
Output is correct |
21 |
Correct |
6 ms |
9504 KB |
Output is correct |
22 |
Correct |
6 ms |
9496 KB |
Output is correct |
23 |
Correct |
6 ms |
9428 KB |
Output is correct |
24 |
Correct |
6 ms |
9400 KB |
Output is correct |
25 |
Correct |
7 ms |
9428 KB |
Output is correct |
26 |
Correct |
6 ms |
9488 KB |
Output is correct |
27 |
Correct |
7 ms |
9436 KB |
Output is correct |
28 |
Correct |
6 ms |
9428 KB |
Output is correct |
29 |
Correct |
10 ms |
9684 KB |
Output is correct |
30 |
Correct |
9 ms |
9556 KB |
Output is correct |
31 |
Correct |
9 ms |
9580 KB |
Output is correct |
32 |
Correct |
9 ms |
9428 KB |
Output is correct |
33 |
Correct |
8 ms |
9428 KB |
Output is correct |
34 |
Correct |
12 ms |
9556 KB |
Output is correct |
35 |
Correct |
10 ms |
9684 KB |
Output is correct |
36 |
Correct |
8 ms |
9428 KB |
Output is correct |
37 |
Correct |
10 ms |
9556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9484 KB |
Output is correct |
2 |
Correct |
6 ms |
9460 KB |
Output is correct |
3 |
Correct |
9 ms |
9428 KB |
Output is correct |
4 |
Correct |
6 ms |
9492 KB |
Output is correct |
5 |
Correct |
6 ms |
9428 KB |
Output is correct |
6 |
Correct |
6 ms |
9540 KB |
Output is correct |
7 |
Correct |
9 ms |
9480 KB |
Output is correct |
8 |
Correct |
6 ms |
9428 KB |
Output is correct |
9 |
Correct |
7 ms |
9428 KB |
Output is correct |
10 |
Correct |
6 ms |
9536 KB |
Output is correct |
11 |
Correct |
7 ms |
9512 KB |
Output is correct |
12 |
Correct |
6 ms |
9500 KB |
Output is correct |
13 |
Correct |
8 ms |
9428 KB |
Output is correct |
14 |
Correct |
5 ms |
9428 KB |
Output is correct |
15 |
Correct |
5 ms |
9484 KB |
Output is correct |
16 |
Correct |
6 ms |
9556 KB |
Output is correct |
17 |
Correct |
8 ms |
9460 KB |
Output is correct |
18 |
Correct |
6 ms |
9496 KB |
Output is correct |
19 |
Correct |
6 ms |
9488 KB |
Output is correct |
20 |
Correct |
6 ms |
9428 KB |
Output is correct |
21 |
Correct |
6 ms |
9504 KB |
Output is correct |
22 |
Correct |
6 ms |
9496 KB |
Output is correct |
23 |
Correct |
6 ms |
9428 KB |
Output is correct |
24 |
Correct |
6 ms |
9400 KB |
Output is correct |
25 |
Correct |
7 ms |
9428 KB |
Output is correct |
26 |
Correct |
6 ms |
9488 KB |
Output is correct |
27 |
Correct |
7 ms |
9436 KB |
Output is correct |
28 |
Correct |
6 ms |
9428 KB |
Output is correct |
29 |
Correct |
10 ms |
9684 KB |
Output is correct |
30 |
Correct |
9 ms |
9556 KB |
Output is correct |
31 |
Correct |
9 ms |
9580 KB |
Output is correct |
32 |
Correct |
9 ms |
9428 KB |
Output is correct |
33 |
Correct |
8 ms |
9428 KB |
Output is correct |
34 |
Correct |
12 ms |
9556 KB |
Output is correct |
35 |
Correct |
10 ms |
9684 KB |
Output is correct |
36 |
Correct |
8 ms |
9428 KB |
Output is correct |
37 |
Correct |
10 ms |
9556 KB |
Output is correct |
38 |
Correct |
405 ms |
24564 KB |
Output is correct |
39 |
Correct |
2482 ms |
265632 KB |
Output is correct |
40 |
Correct |
571 ms |
17776 KB |
Output is correct |
41 |
Correct |
531 ms |
10956 KB |
Output is correct |
42 |
Correct |
265 ms |
15308 KB |
Output is correct |
43 |
Correct |
51 ms |
10992 KB |
Output is correct |
44 |
Correct |
63 ms |
10000 KB |
Output is correct |
45 |
Correct |
1520 ms |
15308 KB |
Output is correct |
46 |
Correct |
1717 ms |
15376 KB |
Output is correct |
47 |
Correct |
827 ms |
66992 KB |
Output is correct |
48 |
Correct |
864 ms |
68076 KB |
Output is correct |
49 |
Correct |
1276 ms |
17668 KB |
Output is correct |
50 |
Correct |
1207 ms |
17740 KB |
Output is correct |
51 |
Correct |
247 ms |
15052 KB |
Output is correct |
52 |
Correct |
276 ms |
15860 KB |
Output is correct |
53 |
Correct |
56 ms |
9884 KB |
Output is correct |
54 |
Correct |
1803 ms |
14880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9428 KB |
Output is correct |
2 |
Correct |
6 ms |
9488 KB |
Output is correct |
3 |
Correct |
6 ms |
9444 KB |
Output is correct |
4 |
Correct |
6 ms |
9488 KB |
Output is correct |
5 |
Correct |
13 ms |
9600 KB |
Output is correct |
6 |
Correct |
7 ms |
9500 KB |
Output is correct |
7 |
Correct |
7 ms |
9428 KB |
Output is correct |
8 |
Correct |
7 ms |
9428 KB |
Output is correct |
9 |
Correct |
6 ms |
9556 KB |
Output is correct |
10 |
Correct |
6 ms |
9428 KB |
Output is correct |
11 |
Correct |
5 ms |
9428 KB |
Output is correct |
12 |
Correct |
8 ms |
9556 KB |
Output is correct |
13 |
Correct |
33 ms |
9904 KB |
Output is correct |
14 |
Correct |
48 ms |
10376 KB |
Output is correct |
15 |
Correct |
43 ms |
10016 KB |
Output is correct |
16 |
Execution timed out |
5088 ms |
15008 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9428 KB |
Output is correct |
2 |
Correct |
5 ms |
9436 KB |
Output is correct |
3 |
Correct |
5 ms |
9428 KB |
Output is correct |
4 |
Correct |
14 ms |
9496 KB |
Output is correct |
5 |
Correct |
23 ms |
9428 KB |
Output is correct |
6 |
Correct |
6 ms |
9556 KB |
Output is correct |
7 |
Correct |
5 ms |
9428 KB |
Output is correct |
8 |
Correct |
9 ms |
9684 KB |
Output is correct |
9 |
Correct |
377 ms |
24876 KB |
Output is correct |
10 |
Correct |
2222 ms |
265356 KB |
Output is correct |
11 |
Correct |
10 ms |
9644 KB |
Output is correct |
12 |
Correct |
63 ms |
10520 KB |
Output is correct |
13 |
Execution timed out |
5022 ms |
28400 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |