# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
887649 |
2023-12-14T23:51:23 Z |
TAhmed33 |
Jail (JOI22_jail) |
C++ |
|
1797 ms |
1048576 KB |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 120025;
vector <int> adj[MAXN];
vector <int> adj2[501];
int n, m;
int l[501], r[501], deg[501];
vector <int> dd[MAXN];
vector <int> ls[501];
bool dfs (int pos, int par, int c) {
if (pos == r[c]) {
dd[pos].push_back(c);
ls[c].push_back(pos);
return 1;
}
bool f = 0;
for (auto i : adj[pos]) {
if (i != par) {
f |= dfs(i, pos, c);
}
}
if (f) {
dd[pos].push_back(c);
ls[c].push_back(pos);
}
return f;
}
int mx1[MAXN], mx2[MAXN];
void solve () {
cin >> m;
vector <pair <int, int>> gg, ff, xx;
for (int i = 0; i < m; i++) {
int l, r;
cin >> l >> r;
if (r < l) ff.push_back({r, l}), swap(l, r);
else gg.push_back({l, r});
xx.push_back({l, r});
}
for (int i = 0; i <= n + 1; i++) mx1[i] = mx2[i] = 0;
sort(xx.begin(), xx.end(), [] (pair <int, int> a, pair <int, int> b) {
return a.first == b.first ? a.second > b.second : a.first < b.first;
});
reverse(xx.begin(), xx.end());
set <int> dd;
bool flag = 0;
for (auto [j, k] : xx) {
//cout << j << " " << k << '\n';
if (!dd.empty()) flag |= *(dd.begin()) <= k;
dd.insert(k);
}
if (flag) {
cout << "No\n";
return;
}
for (auto [j, k] : gg) {
mx1[j] = max(mx1[j], k);
}
for (auto [j, k] : ff) {
mx2[j] = max(mx2[j], k);
}
for (int i = 1; i <= n; i++) {
mx1[i] = max(mx1[i], mx1[i - 1]);
mx2[i] = max(mx2[i], mx2[i - 1]);
}
for (auto [j, k] : gg) {
flag |= mx2[j] >= j;
}
for (auto [j, k] : ff) {
flag |= mx1[j] >= j;
}
cout << (flag ? "No\n" : "Yes\n");
}
int main () {
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; cin >> t;
while (t--) {
cin >> n;
bool flag6 = 1;
for (int i = 1; i <= n; i++) {
adj[i].clear();
dd[i].clear();
}
for (int i = 1; i < n; i++) {
int a, b;
cin >> a >> b;
flag6 &= a == i && b == i + 1;
adj[a].push_back(b);
adj[b].push_back(a);
}
if (flag6) {
solve();
continue;
}
cin >> m;
for (int i = 1; i <= m; i++) {
deg[i] = 0; adj2[i].clear(); ls[i].clear();
}
for (int i = 1; i <= m; i++) {
cin >> l[i] >> r[i];
dfs(l[i], -1, i);
}
for (int i = 1; i <= n; i++) sort(dd[i].begin(), dd[i].end());
bool flag3 = 0;
for (int i = 1; i <= m; i++) {
set <int> y;
for (auto j : dd[l[i]]) y.insert(j);
bool u2 = 0;
for (auto j : dd[r[i]]) u2 |= y.count(j) && j != i;
flag3 |= u2;
u2 = 0;
for (auto j : dd[l[i]]) if (j != i) u2 |= binary_search(dd[l[j]].begin(), dd[l[j]].end(), i);
for (auto j : dd[r[i]]) if (j != i) u2 |= binary_search(dd[r[j]].begin(), dd[r[j]].end(), i);
flag3 |= u2;
}
if (flag3) {
cout << "No\n";
continue;
}
for (int i = 1; i <= m; i++) sort(ls[i].begin(), ls[i].end());
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= m; j++) {
if (i == j) continue;
bool flag = 0;
flag |= binary_search(ls[i].begin(), ls[i].end(), l[j]);
flag |= binary_search(ls[j].begin(), ls[j].end(), r[i]);
if (flag) adj2[i].push_back(j);
}
}
for (int i = 1; i <= m; i++) {
for (auto j : adj2[i]) {
deg[j]++;
}
}
vector <int> d;
queue <int> cur;
for (int i = 1; i <= m; i++) {
if (deg[i] == 0) {
cur.push(i);
}
}
while (!cur.empty()) {
auto j = cur.front();
cur.pop();
d.push_back(j);
for (auto z : adj2[j]) {
deg[z]--;
if (deg[z] == 0) cur.push(z);
}
}
if ((int)d.size() != m) {
cout << "No\n";
} else {
cout << "Yes\n";
}
}
}
Compilation message
jail.cpp: In function 'void solve()':
jail.cpp:46:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
46 | for (auto [j, k] : xx) {
| ^
jail.cpp:55:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
55 | for (auto [j, k] : gg) {
| ^
jail.cpp:58:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
58 | for (auto [j, k] : ff) {
| ^
jail.cpp:65:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
65 | for (auto [j, k] : gg) {
| ^
jail.cpp:68:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
68 | for (auto [j, k] : ff) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6752 KB |
Output is correct |
2 |
Correct |
1 ms |
6744 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
7 ms |
6748 KB |
Output is correct |
5 |
Correct |
12 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6908 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
9 |
Correct |
17 ms |
7004 KB |
Output is correct |
10 |
Correct |
26 ms |
11092 KB |
Output is correct |
11 |
Correct |
4 ms |
6748 KB |
Output is correct |
12 |
Correct |
19 ms |
6916 KB |
Output is correct |
13 |
Correct |
38 ms |
14208 KB |
Output is correct |
14 |
Correct |
37 ms |
15964 KB |
Output is correct |
15 |
Correct |
54 ms |
15428 KB |
Output is correct |
16 |
Correct |
76 ms |
19256 KB |
Output is correct |
17 |
Correct |
41 ms |
16584 KB |
Output is correct |
18 |
Correct |
61 ms |
21100 KB |
Output is correct |
19 |
Correct |
40 ms |
16504 KB |
Output is correct |
20 |
Correct |
40 ms |
16500 KB |
Output is correct |
21 |
Correct |
55 ms |
16572 KB |
Output is correct |
22 |
Correct |
40 ms |
16504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6744 KB |
Output is correct |
3 |
Correct |
2 ms |
6748 KB |
Output is correct |
4 |
Correct |
2 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6744 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
2 ms |
6748 KB |
Output is correct |
11 |
Correct |
3 ms |
6748 KB |
Output is correct |
12 |
Correct |
2 ms |
6748 KB |
Output is correct |
13 |
Correct |
2 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6744 KB |
Output is correct |
3 |
Correct |
2 ms |
6748 KB |
Output is correct |
4 |
Correct |
2 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6744 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
2 ms |
6748 KB |
Output is correct |
11 |
Correct |
3 ms |
6748 KB |
Output is correct |
12 |
Correct |
2 ms |
6748 KB |
Output is correct |
13 |
Correct |
2 ms |
6748 KB |
Output is correct |
14 |
Correct |
1 ms |
6748 KB |
Output is correct |
15 |
Correct |
1 ms |
6776 KB |
Output is correct |
16 |
Correct |
2 ms |
6748 KB |
Output is correct |
17 |
Correct |
2 ms |
6748 KB |
Output is correct |
18 |
Correct |
2 ms |
6748 KB |
Output is correct |
19 |
Correct |
1 ms |
6748 KB |
Output is correct |
20 |
Correct |
2 ms |
6748 KB |
Output is correct |
21 |
Correct |
2 ms |
6748 KB |
Output is correct |
22 |
Correct |
2 ms |
6748 KB |
Output is correct |
23 |
Correct |
1 ms |
6744 KB |
Output is correct |
24 |
Correct |
1 ms |
6748 KB |
Output is correct |
25 |
Correct |
2 ms |
6748 KB |
Output is correct |
26 |
Correct |
1 ms |
6748 KB |
Output is correct |
27 |
Correct |
2 ms |
6924 KB |
Output is correct |
28 |
Correct |
2 ms |
6744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6744 KB |
Output is correct |
3 |
Correct |
2 ms |
6748 KB |
Output is correct |
4 |
Correct |
2 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6744 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
2 ms |
6748 KB |
Output is correct |
11 |
Correct |
3 ms |
6748 KB |
Output is correct |
12 |
Correct |
2 ms |
6748 KB |
Output is correct |
13 |
Correct |
2 ms |
6748 KB |
Output is correct |
14 |
Correct |
1 ms |
6748 KB |
Output is correct |
15 |
Correct |
1 ms |
6776 KB |
Output is correct |
16 |
Correct |
2 ms |
6748 KB |
Output is correct |
17 |
Correct |
2 ms |
6748 KB |
Output is correct |
18 |
Correct |
2 ms |
6748 KB |
Output is correct |
19 |
Correct |
1 ms |
6748 KB |
Output is correct |
20 |
Correct |
2 ms |
6748 KB |
Output is correct |
21 |
Correct |
2 ms |
6748 KB |
Output is correct |
22 |
Correct |
2 ms |
6748 KB |
Output is correct |
23 |
Correct |
1 ms |
6744 KB |
Output is correct |
24 |
Correct |
1 ms |
6748 KB |
Output is correct |
25 |
Correct |
2 ms |
6748 KB |
Output is correct |
26 |
Correct |
1 ms |
6748 KB |
Output is correct |
27 |
Correct |
2 ms |
6924 KB |
Output is correct |
28 |
Correct |
2 ms |
6744 KB |
Output is correct |
29 |
Correct |
2 ms |
6744 KB |
Output is correct |
30 |
Correct |
4 ms |
7188 KB |
Output is correct |
31 |
Correct |
5 ms |
7004 KB |
Output is correct |
32 |
Correct |
5 ms |
6840 KB |
Output is correct |
33 |
Correct |
2 ms |
6748 KB |
Output is correct |
34 |
Correct |
8 ms |
6748 KB |
Output is correct |
35 |
Correct |
10 ms |
7004 KB |
Output is correct |
36 |
Correct |
7 ms |
6940 KB |
Output is correct |
37 |
Correct |
7 ms |
6744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6744 KB |
Output is correct |
3 |
Correct |
2 ms |
6748 KB |
Output is correct |
4 |
Correct |
2 ms |
6748 KB |
Output is correct |
5 |
Correct |
2 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6744 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
2 ms |
6748 KB |
Output is correct |
11 |
Correct |
3 ms |
6748 KB |
Output is correct |
12 |
Correct |
2 ms |
6748 KB |
Output is correct |
13 |
Correct |
2 ms |
6748 KB |
Output is correct |
14 |
Correct |
1 ms |
6748 KB |
Output is correct |
15 |
Correct |
1 ms |
6776 KB |
Output is correct |
16 |
Correct |
2 ms |
6748 KB |
Output is correct |
17 |
Correct |
2 ms |
6748 KB |
Output is correct |
18 |
Correct |
2 ms |
6748 KB |
Output is correct |
19 |
Correct |
1 ms |
6748 KB |
Output is correct |
20 |
Correct |
2 ms |
6748 KB |
Output is correct |
21 |
Correct |
2 ms |
6748 KB |
Output is correct |
22 |
Correct |
2 ms |
6748 KB |
Output is correct |
23 |
Correct |
1 ms |
6744 KB |
Output is correct |
24 |
Correct |
1 ms |
6748 KB |
Output is correct |
25 |
Correct |
2 ms |
6748 KB |
Output is correct |
26 |
Correct |
1 ms |
6748 KB |
Output is correct |
27 |
Correct |
2 ms |
6924 KB |
Output is correct |
28 |
Correct |
2 ms |
6744 KB |
Output is correct |
29 |
Correct |
2 ms |
6744 KB |
Output is correct |
30 |
Correct |
4 ms |
7188 KB |
Output is correct |
31 |
Correct |
5 ms |
7004 KB |
Output is correct |
32 |
Correct |
5 ms |
6840 KB |
Output is correct |
33 |
Correct |
2 ms |
6748 KB |
Output is correct |
34 |
Correct |
8 ms |
6748 KB |
Output is correct |
35 |
Correct |
10 ms |
7004 KB |
Output is correct |
36 |
Correct |
7 ms |
6940 KB |
Output is correct |
37 |
Correct |
7 ms |
6744 KB |
Output is correct |
38 |
Correct |
16 ms |
7004 KB |
Output is correct |
39 |
Correct |
23 ms |
10844 KB |
Output is correct |
40 |
Correct |
758 ms |
17932 KB |
Output is correct |
41 |
Correct |
694 ms |
7816 KB |
Output is correct |
42 |
Correct |
357 ms |
17492 KB |
Output is correct |
43 |
Correct |
42 ms |
7256 KB |
Output is correct |
44 |
Correct |
105 ms |
7004 KB |
Output is correct |
45 |
Correct |
1797 ms |
12012 KB |
Output is correct |
46 |
Correct |
1733 ms |
11604 KB |
Output is correct |
47 |
Correct |
1083 ms |
102252 KB |
Output is correct |
48 |
Correct |
1092 ms |
105000 KB |
Output is correct |
49 |
Correct |
1085 ms |
16312 KB |
Output is correct |
50 |
Correct |
1127 ms |
16484 KB |
Output is correct |
51 |
Correct |
187 ms |
11936 KB |
Output is correct |
52 |
Correct |
200 ms |
11868 KB |
Output is correct |
53 |
Correct |
127 ms |
7560 KB |
Output is correct |
54 |
Correct |
1285 ms |
10992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6748 KB |
Output is correct |
2 |
Correct |
2 ms |
6744 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
5 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6784 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
1 ms |
6836 KB |
Output is correct |
11 |
Correct |
1 ms |
7000 KB |
Output is correct |
12 |
Correct |
6 ms |
6744 KB |
Output is correct |
13 |
Correct |
39 ms |
7000 KB |
Output is correct |
14 |
Correct |
58 ms |
6908 KB |
Output is correct |
15 |
Correct |
53 ms |
6748 KB |
Output is correct |
16 |
Runtime error |
1088 ms |
1048576 KB |
Execution killed with signal 9 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6752 KB |
Output is correct |
2 |
Correct |
1 ms |
6744 KB |
Output is correct |
3 |
Correct |
1 ms |
6748 KB |
Output is correct |
4 |
Correct |
7 ms |
6748 KB |
Output is correct |
5 |
Correct |
12 ms |
6748 KB |
Output is correct |
6 |
Correct |
2 ms |
6908 KB |
Output is correct |
7 |
Correct |
2 ms |
6748 KB |
Output is correct |
8 |
Correct |
2 ms |
6748 KB |
Output is correct |
9 |
Correct |
17 ms |
7004 KB |
Output is correct |
10 |
Correct |
26 ms |
11092 KB |
Output is correct |
11 |
Correct |
4 ms |
6748 KB |
Output is correct |
12 |
Correct |
19 ms |
6916 KB |
Output is correct |
13 |
Correct |
38 ms |
14208 KB |
Output is correct |
14 |
Correct |
37 ms |
15964 KB |
Output is correct |
15 |
Correct |
54 ms |
15428 KB |
Output is correct |
16 |
Correct |
76 ms |
19256 KB |
Output is correct |
17 |
Correct |
41 ms |
16584 KB |
Output is correct |
18 |
Correct |
61 ms |
21100 KB |
Output is correct |
19 |
Correct |
40 ms |
16504 KB |
Output is correct |
20 |
Correct |
40 ms |
16500 KB |
Output is correct |
21 |
Correct |
55 ms |
16572 KB |
Output is correct |
22 |
Correct |
40 ms |
16504 KB |
Output is correct |
23 |
Correct |
1 ms |
6744 KB |
Output is correct |
24 |
Correct |
1 ms |
6744 KB |
Output is correct |
25 |
Correct |
2 ms |
6748 KB |
Output is correct |
26 |
Correct |
2 ms |
6748 KB |
Output is correct |
27 |
Correct |
2 ms |
6748 KB |
Output is correct |
28 |
Correct |
2 ms |
6744 KB |
Output is correct |
29 |
Correct |
2 ms |
6748 KB |
Output is correct |
30 |
Correct |
2 ms |
6748 KB |
Output is correct |
31 |
Correct |
2 ms |
6748 KB |
Output is correct |
32 |
Correct |
2 ms |
6748 KB |
Output is correct |
33 |
Correct |
3 ms |
6748 KB |
Output is correct |
34 |
Correct |
2 ms |
6748 KB |
Output is correct |
35 |
Correct |
2 ms |
6748 KB |
Output is correct |
36 |
Correct |
1 ms |
6748 KB |
Output is correct |
37 |
Correct |
1 ms |
6776 KB |
Output is correct |
38 |
Correct |
2 ms |
6748 KB |
Output is correct |
39 |
Correct |
2 ms |
6748 KB |
Output is correct |
40 |
Correct |
2 ms |
6748 KB |
Output is correct |
41 |
Correct |
1 ms |
6748 KB |
Output is correct |
42 |
Correct |
2 ms |
6748 KB |
Output is correct |
43 |
Correct |
2 ms |
6748 KB |
Output is correct |
44 |
Correct |
2 ms |
6748 KB |
Output is correct |
45 |
Correct |
1 ms |
6744 KB |
Output is correct |
46 |
Correct |
1 ms |
6748 KB |
Output is correct |
47 |
Correct |
2 ms |
6748 KB |
Output is correct |
48 |
Correct |
1 ms |
6748 KB |
Output is correct |
49 |
Correct |
2 ms |
6924 KB |
Output is correct |
50 |
Correct |
2 ms |
6744 KB |
Output is correct |
51 |
Correct |
2 ms |
6744 KB |
Output is correct |
52 |
Correct |
4 ms |
7188 KB |
Output is correct |
53 |
Correct |
5 ms |
7004 KB |
Output is correct |
54 |
Correct |
5 ms |
6840 KB |
Output is correct |
55 |
Correct |
2 ms |
6748 KB |
Output is correct |
56 |
Correct |
8 ms |
6748 KB |
Output is correct |
57 |
Correct |
10 ms |
7004 KB |
Output is correct |
58 |
Correct |
7 ms |
6940 KB |
Output is correct |
59 |
Correct |
7 ms |
6744 KB |
Output is correct |
60 |
Correct |
16 ms |
7004 KB |
Output is correct |
61 |
Correct |
23 ms |
10844 KB |
Output is correct |
62 |
Correct |
758 ms |
17932 KB |
Output is correct |
63 |
Correct |
694 ms |
7816 KB |
Output is correct |
64 |
Correct |
357 ms |
17492 KB |
Output is correct |
65 |
Correct |
42 ms |
7256 KB |
Output is correct |
66 |
Correct |
105 ms |
7004 KB |
Output is correct |
67 |
Correct |
1797 ms |
12012 KB |
Output is correct |
68 |
Correct |
1733 ms |
11604 KB |
Output is correct |
69 |
Correct |
1083 ms |
102252 KB |
Output is correct |
70 |
Correct |
1092 ms |
105000 KB |
Output is correct |
71 |
Correct |
1085 ms |
16312 KB |
Output is correct |
72 |
Correct |
1127 ms |
16484 KB |
Output is correct |
73 |
Correct |
187 ms |
11936 KB |
Output is correct |
74 |
Correct |
200 ms |
11868 KB |
Output is correct |
75 |
Correct |
127 ms |
7560 KB |
Output is correct |
76 |
Correct |
1285 ms |
10992 KB |
Output is correct |
77 |
Correct |
2 ms |
6748 KB |
Output is correct |
78 |
Correct |
2 ms |
6744 KB |
Output is correct |
79 |
Correct |
1 ms |
6748 KB |
Output is correct |
80 |
Correct |
1 ms |
6748 KB |
Output is correct |
81 |
Correct |
5 ms |
6748 KB |
Output is correct |
82 |
Correct |
2 ms |
6748 KB |
Output is correct |
83 |
Correct |
2 ms |
6784 KB |
Output is correct |
84 |
Correct |
2 ms |
6748 KB |
Output is correct |
85 |
Correct |
2 ms |
6748 KB |
Output is correct |
86 |
Correct |
1 ms |
6836 KB |
Output is correct |
87 |
Correct |
1 ms |
7000 KB |
Output is correct |
88 |
Correct |
6 ms |
6744 KB |
Output is correct |
89 |
Correct |
39 ms |
7000 KB |
Output is correct |
90 |
Correct |
58 ms |
6908 KB |
Output is correct |
91 |
Correct |
53 ms |
6748 KB |
Output is correct |
92 |
Runtime error |
1088 ms |
1048576 KB |
Execution killed with signal 9 |
93 |
Halted |
0 ms |
0 KB |
- |