# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
560914 |
2022-05-12T04:49:36 Z |
8e7 |
Jail (JOI22_jail) |
C++17 |
|
5000 ms |
25220 KB |
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 120005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
vector<int> adj[maxn], g[maxn];
int anc[18][maxn], dep[maxn], deg[maxn];
pii ed[maxn];
void dfs(int n, int par, int d) {
anc[0][n] = par;
dep[n] = d;
for (int v:adj[n]) {
if (v != par) {
dfs(v, n, d + 1);
}
}
}
int lca(int a, int b) {
if (dep[a] < dep[b]) swap(a, b);
int hdif = dep[a] - dep[b], cnt = 0;
while (hdif) {
if (hdif & 1) a = anc[cnt][a];
hdif >>= 1, cnt++;
}
if (a == b) return a;
for (int i = 17;i >= 0;i--) {
if (anc[i][a] != anc[i][b]) {
a = anc[i][a], b = anc[i][b];
}
}
return anc[0][a];
}
int getdis(int u, int v) {
return dep[u] + dep[v] - 2 * dep[lca(u, v)];
}
bool onl(int u, int v, int x) {
return getdis(u, v) == getdis(u, x) + getdis(x, v);
}
int main() {
io
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
for (int i = 1;i <= n;i++) {
adj[i].clear();
g[i].clear();
deg[i] = 0;
}
for (int i = 0;i < n - 1;i++) {
int u,v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1, 0, 0);
for (int i = 1;i < 18;i++) {
for (int j = 1;j <= n;j++) anc[i][j] = anc[i-1][anc[i-1][j]];
}
int m;
cin >> m;
auto addedge = [&] (int u, int v) {
//debug("edge", u, v);
g[u].push_back(v);
deg[v]++;
};
for (int i = 1;i <= m;i++) {
int u, v;
cin >> u >> v;
ed[i] = {u, v};
}
for (int i = 1;i <= m;i++) {
for (int j = i+1;j <= m;j++) {
if (onl(ed[i].ff, ed[i].ss, ed[j].ff)) addedge(j, i);
if (onl(ed[i].ff, ed[i].ss, ed[j].ss)) addedge(i, j);
if (onl(ed[j].ff, ed[j].ss, ed[i].ff)) addedge(i, j);
if (onl(ed[j].ff, ed[j].ss, ed[i].ss)) addedge(j, i);
}
}
queue<int> que;
for (int i = 1;i <= n;i++) {
if (deg[i] == 0) que.push(i);
}
int cnt = 0;
while (que.size()) {
int cur = que.front();que.pop();
cnt++;
for (int v:g[cur]) {
if (--deg[v] == 0) que.push(v);
}
}
cout << (cnt == n ? "Yes" : "No") << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5972 KB |
Output is correct |
2 |
Correct |
4 ms |
5972 KB |
Output is correct |
3 |
Correct |
4 ms |
5972 KB |
Output is correct |
4 |
Correct |
15 ms |
6208 KB |
Output is correct |
5 |
Correct |
24 ms |
6100 KB |
Output is correct |
6 |
Correct |
5 ms |
6112 KB |
Output is correct |
7 |
Correct |
4 ms |
5972 KB |
Output is correct |
8 |
Correct |
33 ms |
6100 KB |
Output is correct |
9 |
Correct |
1220 ms |
9808 KB |
Output is correct |
10 |
Correct |
84 ms |
24676 KB |
Output is correct |
11 |
Correct |
15 ms |
6220 KB |
Output is correct |
12 |
Correct |
399 ms |
7068 KB |
Output is correct |
13 |
Execution timed out |
5033 ms |
24088 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5972 KB |
Output is correct |
2 |
Correct |
4 ms |
5972 KB |
Output is correct |
3 |
Correct |
4 ms |
5972 KB |
Output is correct |
4 |
Correct |
4 ms |
6080 KB |
Output is correct |
5 |
Correct |
5 ms |
6100 KB |
Output is correct |
6 |
Correct |
4 ms |
6100 KB |
Output is correct |
7 |
Correct |
4 ms |
6100 KB |
Output is correct |
8 |
Correct |
4 ms |
6100 KB |
Output is correct |
9 |
Correct |
5 ms |
6100 KB |
Output is correct |
10 |
Correct |
6 ms |
6100 KB |
Output is correct |
11 |
Correct |
4 ms |
6100 KB |
Output is correct |
12 |
Correct |
4 ms |
6100 KB |
Output is correct |
13 |
Correct |
4 ms |
6100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5972 KB |
Output is correct |
2 |
Correct |
4 ms |
5972 KB |
Output is correct |
3 |
Correct |
4 ms |
5972 KB |
Output is correct |
4 |
Correct |
4 ms |
6080 KB |
Output is correct |
5 |
Correct |
5 ms |
6100 KB |
Output is correct |
6 |
Correct |
4 ms |
6100 KB |
Output is correct |
7 |
Correct |
4 ms |
6100 KB |
Output is correct |
8 |
Correct |
4 ms |
6100 KB |
Output is correct |
9 |
Correct |
5 ms |
6100 KB |
Output is correct |
10 |
Correct |
6 ms |
6100 KB |
Output is correct |
11 |
Correct |
4 ms |
6100 KB |
Output is correct |
12 |
Correct |
4 ms |
6100 KB |
Output is correct |
13 |
Correct |
4 ms |
6100 KB |
Output is correct |
14 |
Correct |
3 ms |
5972 KB |
Output is correct |
15 |
Correct |
3 ms |
5972 KB |
Output is correct |
16 |
Correct |
4 ms |
6100 KB |
Output is correct |
17 |
Correct |
4 ms |
6100 KB |
Output is correct |
18 |
Correct |
5 ms |
6056 KB |
Output is correct |
19 |
Correct |
5 ms |
5972 KB |
Output is correct |
20 |
Correct |
4 ms |
6100 KB |
Output is correct |
21 |
Correct |
4 ms |
6100 KB |
Output is correct |
22 |
Correct |
5 ms |
6100 KB |
Output is correct |
23 |
Correct |
3 ms |
5972 KB |
Output is correct |
24 |
Correct |
4 ms |
5964 KB |
Output is correct |
25 |
Correct |
5 ms |
6100 KB |
Output is correct |
26 |
Correct |
6 ms |
5972 KB |
Output is correct |
27 |
Correct |
5 ms |
6100 KB |
Output is correct |
28 |
Correct |
4 ms |
5972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5972 KB |
Output is correct |
2 |
Correct |
4 ms |
5972 KB |
Output is correct |
3 |
Correct |
4 ms |
5972 KB |
Output is correct |
4 |
Correct |
4 ms |
6080 KB |
Output is correct |
5 |
Correct |
5 ms |
6100 KB |
Output is correct |
6 |
Correct |
4 ms |
6100 KB |
Output is correct |
7 |
Correct |
4 ms |
6100 KB |
Output is correct |
8 |
Correct |
4 ms |
6100 KB |
Output is correct |
9 |
Correct |
5 ms |
6100 KB |
Output is correct |
10 |
Correct |
6 ms |
6100 KB |
Output is correct |
11 |
Correct |
4 ms |
6100 KB |
Output is correct |
12 |
Correct |
4 ms |
6100 KB |
Output is correct |
13 |
Correct |
4 ms |
6100 KB |
Output is correct |
14 |
Correct |
3 ms |
5972 KB |
Output is correct |
15 |
Correct |
3 ms |
5972 KB |
Output is correct |
16 |
Correct |
4 ms |
6100 KB |
Output is correct |
17 |
Correct |
4 ms |
6100 KB |
Output is correct |
18 |
Correct |
5 ms |
6056 KB |
Output is correct |
19 |
Correct |
5 ms |
5972 KB |
Output is correct |
20 |
Correct |
4 ms |
6100 KB |
Output is correct |
21 |
Correct |
4 ms |
6100 KB |
Output is correct |
22 |
Correct |
5 ms |
6100 KB |
Output is correct |
23 |
Correct |
3 ms |
5972 KB |
Output is correct |
24 |
Correct |
4 ms |
5964 KB |
Output is correct |
25 |
Correct |
5 ms |
6100 KB |
Output is correct |
26 |
Correct |
6 ms |
5972 KB |
Output is correct |
27 |
Correct |
5 ms |
6100 KB |
Output is correct |
28 |
Correct |
4 ms |
5972 KB |
Output is correct |
29 |
Correct |
35 ms |
6140 KB |
Output is correct |
30 |
Correct |
21 ms |
6152 KB |
Output is correct |
31 |
Correct |
25 ms |
6100 KB |
Output is correct |
32 |
Correct |
15 ms |
6084 KB |
Output is correct |
33 |
Correct |
6 ms |
6100 KB |
Output is correct |
34 |
Correct |
39 ms |
6144 KB |
Output is correct |
35 |
Correct |
54 ms |
6172 KB |
Output is correct |
36 |
Correct |
28 ms |
6116 KB |
Output is correct |
37 |
Correct |
25 ms |
6100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5972 KB |
Output is correct |
2 |
Correct |
4 ms |
5972 KB |
Output is correct |
3 |
Correct |
4 ms |
5972 KB |
Output is correct |
4 |
Correct |
4 ms |
6080 KB |
Output is correct |
5 |
Correct |
5 ms |
6100 KB |
Output is correct |
6 |
Correct |
4 ms |
6100 KB |
Output is correct |
7 |
Correct |
4 ms |
6100 KB |
Output is correct |
8 |
Correct |
4 ms |
6100 KB |
Output is correct |
9 |
Correct |
5 ms |
6100 KB |
Output is correct |
10 |
Correct |
6 ms |
6100 KB |
Output is correct |
11 |
Correct |
4 ms |
6100 KB |
Output is correct |
12 |
Correct |
4 ms |
6100 KB |
Output is correct |
13 |
Correct |
4 ms |
6100 KB |
Output is correct |
14 |
Correct |
3 ms |
5972 KB |
Output is correct |
15 |
Correct |
3 ms |
5972 KB |
Output is correct |
16 |
Correct |
4 ms |
6100 KB |
Output is correct |
17 |
Correct |
4 ms |
6100 KB |
Output is correct |
18 |
Correct |
5 ms |
6056 KB |
Output is correct |
19 |
Correct |
5 ms |
5972 KB |
Output is correct |
20 |
Correct |
4 ms |
6100 KB |
Output is correct |
21 |
Correct |
4 ms |
6100 KB |
Output is correct |
22 |
Correct |
5 ms |
6100 KB |
Output is correct |
23 |
Correct |
3 ms |
5972 KB |
Output is correct |
24 |
Correct |
4 ms |
5964 KB |
Output is correct |
25 |
Correct |
5 ms |
6100 KB |
Output is correct |
26 |
Correct |
6 ms |
5972 KB |
Output is correct |
27 |
Correct |
5 ms |
6100 KB |
Output is correct |
28 |
Correct |
4 ms |
5972 KB |
Output is correct |
29 |
Correct |
35 ms |
6140 KB |
Output is correct |
30 |
Correct |
21 ms |
6152 KB |
Output is correct |
31 |
Correct |
25 ms |
6100 KB |
Output is correct |
32 |
Correct |
15 ms |
6084 KB |
Output is correct |
33 |
Correct |
6 ms |
6100 KB |
Output is correct |
34 |
Correct |
39 ms |
6144 KB |
Output is correct |
35 |
Correct |
54 ms |
6172 KB |
Output is correct |
36 |
Correct |
28 ms |
6116 KB |
Output is correct |
37 |
Correct |
25 ms |
6100 KB |
Output is correct |
38 |
Correct |
1176 ms |
8984 KB |
Output is correct |
39 |
Correct |
95 ms |
25220 KB |
Output is correct |
40 |
Correct |
1462 ms |
9200 KB |
Output is correct |
41 |
Correct |
1184 ms |
7796 KB |
Output is correct |
42 |
Correct |
976 ms |
9464 KB |
Output is correct |
43 |
Correct |
40 ms |
7920 KB |
Output is correct |
44 |
Correct |
767 ms |
6632 KB |
Output is correct |
45 |
Correct |
197 ms |
21072 KB |
Output is correct |
46 |
Correct |
214 ms |
20928 KB |
Output is correct |
47 |
Correct |
183 ms |
22484 KB |
Output is correct |
48 |
Correct |
174 ms |
22564 KB |
Output is correct |
49 |
Correct |
201 ms |
21112 KB |
Output is correct |
50 |
Correct |
203 ms |
20940 KB |
Output is correct |
51 |
Correct |
64 ms |
20492 KB |
Output is correct |
52 |
Correct |
59 ms |
21308 KB |
Output is correct |
53 |
Correct |
598 ms |
7208 KB |
Output is correct |
54 |
Correct |
148 ms |
20920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5972 KB |
Output is correct |
2 |
Correct |
3 ms |
6020 KB |
Output is correct |
3 |
Correct |
3 ms |
5972 KB |
Output is correct |
4 |
Correct |
3 ms |
5972 KB |
Output is correct |
5 |
Correct |
15 ms |
6072 KB |
Output is correct |
6 |
Correct |
4 ms |
5972 KB |
Output is correct |
7 |
Correct |
4 ms |
5972 KB |
Output is correct |
8 |
Correct |
5 ms |
6036 KB |
Output is correct |
9 |
Correct |
3 ms |
5972 KB |
Output is correct |
10 |
Correct |
3 ms |
5972 KB |
Output is correct |
11 |
Correct |
4 ms |
5972 KB |
Output is correct |
12 |
Correct |
30 ms |
6100 KB |
Output is correct |
13 |
Correct |
367 ms |
6136 KB |
Output is correct |
14 |
Correct |
190 ms |
6068 KB |
Output is correct |
15 |
Correct |
285 ms |
6076 KB |
Output is correct |
16 |
Execution timed out |
5090 ms |
19376 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5972 KB |
Output is correct |
2 |
Correct |
4 ms |
5972 KB |
Output is correct |
3 |
Correct |
4 ms |
5972 KB |
Output is correct |
4 |
Correct |
15 ms |
6208 KB |
Output is correct |
5 |
Correct |
24 ms |
6100 KB |
Output is correct |
6 |
Correct |
5 ms |
6112 KB |
Output is correct |
7 |
Correct |
4 ms |
5972 KB |
Output is correct |
8 |
Correct |
33 ms |
6100 KB |
Output is correct |
9 |
Correct |
1220 ms |
9808 KB |
Output is correct |
10 |
Correct |
84 ms |
24676 KB |
Output is correct |
11 |
Correct |
15 ms |
6220 KB |
Output is correct |
12 |
Correct |
399 ms |
7068 KB |
Output is correct |
13 |
Execution timed out |
5033 ms |
24088 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |