# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
560887 |
2022-05-12T04:34:36 Z |
8e7 |
Jail (JOI22_jail) |
C++17 |
|
5000 ms |
1048576 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];
set<int> path[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 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();
path[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);
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;
int tu = u, tv = v;
while (tu != tv) {
if (dep[tu] < dep[tv]) swap(tu, tv);
path[i].insert(tu);
tu = anc[0][tu];
}
path[i].insert(tu);
ed[i] = {u, v};
}
for (int i = 1;i <= m;i++) {
for (int j = i+1;j <= m;j++) {
if (path[i].find(ed[j].ff) != path[i].end()) addedge(j, i);
if (path[i].find(ed[j].ss) != path[i].end()) addedge(i, j);
if (path[j].find(ed[i].ff) != path[j].end()) addedge(i, j);
if (path[j].find(ed[i].ss) != path[j].end()) 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";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
11604 KB |
Output is correct |
2 |
Correct |
7 ms |
11604 KB |
Output is correct |
3 |
Correct |
6 ms |
11604 KB |
Output is correct |
4 |
Correct |
22 ms |
11772 KB |
Output is correct |
5 |
Correct |
41 ms |
11788 KB |
Output is correct |
6 |
Correct |
7 ms |
11612 KB |
Output is correct |
7 |
Correct |
8 ms |
11604 KB |
Output is correct |
8 |
Correct |
19 ms |
12376 KB |
Output is correct |
9 |
Correct |
2274 ms |
144028 KB |
Output is correct |
10 |
Runtime error |
4588 ms |
1048576 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
11604 KB |
Output is correct |
2 |
Correct |
7 ms |
11560 KB |
Output is correct |
3 |
Correct |
7 ms |
11616 KB |
Output is correct |
4 |
Correct |
7 ms |
11608 KB |
Output is correct |
5 |
Correct |
8 ms |
11616 KB |
Output is correct |
6 |
Correct |
7 ms |
11604 KB |
Output is correct |
7 |
Correct |
9 ms |
11680 KB |
Output is correct |
8 |
Correct |
8 ms |
11604 KB |
Output is correct |
9 |
Correct |
8 ms |
11604 KB |
Output is correct |
10 |
Correct |
10 ms |
11588 KB |
Output is correct |
11 |
Correct |
8 ms |
11608 KB |
Output is correct |
12 |
Correct |
7 ms |
11604 KB |
Output is correct |
13 |
Correct |
8 ms |
11604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
11604 KB |
Output is correct |
2 |
Correct |
7 ms |
11560 KB |
Output is correct |
3 |
Correct |
7 ms |
11616 KB |
Output is correct |
4 |
Correct |
7 ms |
11608 KB |
Output is correct |
5 |
Correct |
8 ms |
11616 KB |
Output is correct |
6 |
Correct |
7 ms |
11604 KB |
Output is correct |
7 |
Correct |
9 ms |
11680 KB |
Output is correct |
8 |
Correct |
8 ms |
11604 KB |
Output is correct |
9 |
Correct |
8 ms |
11604 KB |
Output is correct |
10 |
Correct |
10 ms |
11588 KB |
Output is correct |
11 |
Correct |
8 ms |
11608 KB |
Output is correct |
12 |
Correct |
7 ms |
11604 KB |
Output is correct |
13 |
Correct |
8 ms |
11604 KB |
Output is correct |
14 |
Correct |
6 ms |
11604 KB |
Output is correct |
15 |
Correct |
6 ms |
11604 KB |
Output is correct |
16 |
Correct |
8 ms |
11696 KB |
Output is correct |
17 |
Correct |
7 ms |
11560 KB |
Output is correct |
18 |
Correct |
8 ms |
11688 KB |
Output is correct |
19 |
Correct |
7 ms |
11604 KB |
Output is correct |
20 |
Correct |
7 ms |
11676 KB |
Output is correct |
21 |
Correct |
7 ms |
11604 KB |
Output is correct |
22 |
Correct |
8 ms |
11656 KB |
Output is correct |
23 |
Correct |
7 ms |
11604 KB |
Output is correct |
24 |
Correct |
7 ms |
11604 KB |
Output is correct |
25 |
Correct |
9 ms |
11644 KB |
Output is correct |
26 |
Correct |
7 ms |
11604 KB |
Output is correct |
27 |
Correct |
7 ms |
11648 KB |
Output is correct |
28 |
Correct |
6 ms |
11604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
11604 KB |
Output is correct |
2 |
Correct |
7 ms |
11560 KB |
Output is correct |
3 |
Correct |
7 ms |
11616 KB |
Output is correct |
4 |
Correct |
7 ms |
11608 KB |
Output is correct |
5 |
Correct |
8 ms |
11616 KB |
Output is correct |
6 |
Correct |
7 ms |
11604 KB |
Output is correct |
7 |
Correct |
9 ms |
11680 KB |
Output is correct |
8 |
Correct |
8 ms |
11604 KB |
Output is correct |
9 |
Correct |
8 ms |
11604 KB |
Output is correct |
10 |
Correct |
10 ms |
11588 KB |
Output is correct |
11 |
Correct |
8 ms |
11608 KB |
Output is correct |
12 |
Correct |
7 ms |
11604 KB |
Output is correct |
13 |
Correct |
8 ms |
11604 KB |
Output is correct |
14 |
Correct |
6 ms |
11604 KB |
Output is correct |
15 |
Correct |
6 ms |
11604 KB |
Output is correct |
16 |
Correct |
8 ms |
11696 KB |
Output is correct |
17 |
Correct |
7 ms |
11560 KB |
Output is correct |
18 |
Correct |
8 ms |
11688 KB |
Output is correct |
19 |
Correct |
7 ms |
11604 KB |
Output is correct |
20 |
Correct |
7 ms |
11676 KB |
Output is correct |
21 |
Correct |
7 ms |
11604 KB |
Output is correct |
22 |
Correct |
8 ms |
11656 KB |
Output is correct |
23 |
Correct |
7 ms |
11604 KB |
Output is correct |
24 |
Correct |
7 ms |
11604 KB |
Output is correct |
25 |
Correct |
9 ms |
11644 KB |
Output is correct |
26 |
Correct |
7 ms |
11604 KB |
Output is correct |
27 |
Correct |
7 ms |
11648 KB |
Output is correct |
28 |
Correct |
6 ms |
11604 KB |
Output is correct |
29 |
Correct |
20 ms |
12476 KB |
Output is correct |
30 |
Correct |
11 ms |
11744 KB |
Output is correct |
31 |
Correct |
14 ms |
11888 KB |
Output is correct |
32 |
Correct |
11 ms |
11732 KB |
Output is correct |
33 |
Correct |
9 ms |
11620 KB |
Output is correct |
34 |
Correct |
13 ms |
11732 KB |
Output is correct |
35 |
Correct |
30 ms |
12136 KB |
Output is correct |
36 |
Correct |
12 ms |
11700 KB |
Output is correct |
37 |
Correct |
12 ms |
11604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
11604 KB |
Output is correct |
2 |
Correct |
7 ms |
11560 KB |
Output is correct |
3 |
Correct |
7 ms |
11616 KB |
Output is correct |
4 |
Correct |
7 ms |
11608 KB |
Output is correct |
5 |
Correct |
8 ms |
11616 KB |
Output is correct |
6 |
Correct |
7 ms |
11604 KB |
Output is correct |
7 |
Correct |
9 ms |
11680 KB |
Output is correct |
8 |
Correct |
8 ms |
11604 KB |
Output is correct |
9 |
Correct |
8 ms |
11604 KB |
Output is correct |
10 |
Correct |
10 ms |
11588 KB |
Output is correct |
11 |
Correct |
8 ms |
11608 KB |
Output is correct |
12 |
Correct |
7 ms |
11604 KB |
Output is correct |
13 |
Correct |
8 ms |
11604 KB |
Output is correct |
14 |
Correct |
6 ms |
11604 KB |
Output is correct |
15 |
Correct |
6 ms |
11604 KB |
Output is correct |
16 |
Correct |
8 ms |
11696 KB |
Output is correct |
17 |
Correct |
7 ms |
11560 KB |
Output is correct |
18 |
Correct |
8 ms |
11688 KB |
Output is correct |
19 |
Correct |
7 ms |
11604 KB |
Output is correct |
20 |
Correct |
7 ms |
11676 KB |
Output is correct |
21 |
Correct |
7 ms |
11604 KB |
Output is correct |
22 |
Correct |
8 ms |
11656 KB |
Output is correct |
23 |
Correct |
7 ms |
11604 KB |
Output is correct |
24 |
Correct |
7 ms |
11604 KB |
Output is correct |
25 |
Correct |
9 ms |
11644 KB |
Output is correct |
26 |
Correct |
7 ms |
11604 KB |
Output is correct |
27 |
Correct |
7 ms |
11648 KB |
Output is correct |
28 |
Correct |
6 ms |
11604 KB |
Output is correct |
29 |
Correct |
20 ms |
12476 KB |
Output is correct |
30 |
Correct |
11 ms |
11744 KB |
Output is correct |
31 |
Correct |
14 ms |
11888 KB |
Output is correct |
32 |
Correct |
11 ms |
11732 KB |
Output is correct |
33 |
Correct |
9 ms |
11620 KB |
Output is correct |
34 |
Correct |
13 ms |
11732 KB |
Output is correct |
35 |
Correct |
30 ms |
12136 KB |
Output is correct |
36 |
Correct |
12 ms |
11700 KB |
Output is correct |
37 |
Correct |
12 ms |
11604 KB |
Output is correct |
38 |
Correct |
2396 ms |
143784 KB |
Output is correct |
39 |
Runtime error |
4314 ms |
1048576 KB |
Execution killed with signal 9 |
40 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
11604 KB |
Output is correct |
2 |
Correct |
7 ms |
11532 KB |
Output is correct |
3 |
Correct |
7 ms |
11604 KB |
Output is correct |
4 |
Correct |
8 ms |
11604 KB |
Output is correct |
5 |
Correct |
14 ms |
11744 KB |
Output is correct |
6 |
Correct |
6 ms |
11616 KB |
Output is correct |
7 |
Correct |
8 ms |
11604 KB |
Output is correct |
8 |
Correct |
7 ms |
11604 KB |
Output is correct |
9 |
Correct |
7 ms |
11604 KB |
Output is correct |
10 |
Correct |
7 ms |
11604 KB |
Output is correct |
11 |
Correct |
7 ms |
11604 KB |
Output is correct |
12 |
Correct |
13 ms |
11612 KB |
Output is correct |
13 |
Correct |
104 ms |
12176 KB |
Output is correct |
14 |
Correct |
65 ms |
12392 KB |
Output is correct |
15 |
Correct |
83 ms |
12276 KB |
Output is correct |
16 |
Correct |
3911 ms |
27128 KB |
Output is correct |
17 |
Execution timed out |
5048 ms |
63892 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
11604 KB |
Output is correct |
2 |
Correct |
7 ms |
11604 KB |
Output is correct |
3 |
Correct |
6 ms |
11604 KB |
Output is correct |
4 |
Correct |
22 ms |
11772 KB |
Output is correct |
5 |
Correct |
41 ms |
11788 KB |
Output is correct |
6 |
Correct |
7 ms |
11612 KB |
Output is correct |
7 |
Correct |
8 ms |
11604 KB |
Output is correct |
8 |
Correct |
19 ms |
12376 KB |
Output is correct |
9 |
Correct |
2274 ms |
144028 KB |
Output is correct |
10 |
Runtime error |
4588 ms |
1048576 KB |
Execution killed with signal 9 |
11 |
Halted |
0 ms |
0 KB |
- |