# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
560934 |
2022-05-12T05:19:00 Z |
8e7 |
Jail (JOI22_jail) |
C++17 |
|
62 ms |
27308 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], c[2][maxn], rig[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();
deg[i] = 0;
c[0][i] = c[1][i] = 0;
rig[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;
if (u < v) c[0][u]++, c[0][v]--, rig[u] = v;
else c[1][v]++, c[1][u]--, rig[v] = u;
ed[i] = {u, v};
}
bool poss = 1;
int cur = 0;
for (int i = 1;i <= n;i++) {
c[0][i] += c[0][i-1], c[1][i] += c[1][i-1];
if (c[0][i] && c[1][i]) {
poss = 0;
break;
}
if (rig[i] && rig[i] < cur) {
poss = 0;
break;
}
if (rig[i]) cur = rig[i];
}
cout << (poss ? "Yes" : "No") << "\n";
}
}
Compilation message
jail.cpp: In function 'int main()':
jail.cpp:60:8: warning: variable 'addedge' set but not used [-Wunused-but-set-variable]
60 | auto addedge = [&] (int u, int v) {
| ^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5972 KB |
Output is correct |
2 |
Correct |
3 ms |
5972 KB |
Output is correct |
3 |
Correct |
3 ms |
5972 KB |
Output is correct |
4 |
Correct |
10 ms |
6084 KB |
Output is correct |
5 |
Correct |
20 ms |
5972 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 |
23 ms |
6952 KB |
Output is correct |
10 |
Correct |
39 ms |
23640 KB |
Output is correct |
11 |
Correct |
6 ms |
6084 KB |
Output is correct |
12 |
Correct |
24 ms |
6088 KB |
Output is correct |
13 |
Correct |
46 ms |
23996 KB |
Output is correct |
14 |
Correct |
47 ms |
25784 KB |
Output is correct |
15 |
Correct |
49 ms |
25188 KB |
Output is correct |
16 |
Correct |
62 ms |
26808 KB |
Output is correct |
17 |
Correct |
51 ms |
26112 KB |
Output is correct |
18 |
Correct |
60 ms |
27308 KB |
Output is correct |
19 |
Correct |
55 ms |
26080 KB |
Output is correct |
20 |
Correct |
50 ms |
26080 KB |
Output is correct |
21 |
Correct |
49 ms |
26188 KB |
Output is correct |
22 |
Correct |
49 ms |
26072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5972 KB |
Output is correct |
2 |
Correct |
3 ms |
5972 KB |
Output is correct |
3 |
Correct |
5 ms |
6100 KB |
Output is correct |
4 |
Incorrect |
4 ms |
6100 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5972 KB |
Output is correct |
2 |
Correct |
3 ms |
5972 KB |
Output is correct |
3 |
Correct |
5 ms |
6100 KB |
Output is correct |
4 |
Incorrect |
4 ms |
6100 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5972 KB |
Output is correct |
2 |
Correct |
3 ms |
5972 KB |
Output is correct |
3 |
Correct |
5 ms |
6100 KB |
Output is correct |
4 |
Incorrect |
4 ms |
6100 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5972 KB |
Output is correct |
2 |
Correct |
3 ms |
5972 KB |
Output is correct |
3 |
Correct |
5 ms |
6100 KB |
Output is correct |
4 |
Incorrect |
4 ms |
6100 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5972 KB |
Output is correct |
2 |
Correct |
3 ms |
5972 KB |
Output is correct |
3 |
Correct |
3 ms |
5972 KB |
Output is correct |
4 |
Correct |
3 ms |
5972 KB |
Output is correct |
5 |
Correct |
8 ms |
6080 KB |
Output is correct |
6 |
Incorrect |
3 ms |
6100 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5972 KB |
Output is correct |
2 |
Correct |
3 ms |
5972 KB |
Output is correct |
3 |
Correct |
3 ms |
5972 KB |
Output is correct |
4 |
Correct |
10 ms |
6084 KB |
Output is correct |
5 |
Correct |
20 ms |
5972 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 |
23 ms |
6952 KB |
Output is correct |
10 |
Correct |
39 ms |
23640 KB |
Output is correct |
11 |
Correct |
6 ms |
6084 KB |
Output is correct |
12 |
Correct |
24 ms |
6088 KB |
Output is correct |
13 |
Correct |
46 ms |
23996 KB |
Output is correct |
14 |
Correct |
47 ms |
25784 KB |
Output is correct |
15 |
Correct |
49 ms |
25188 KB |
Output is correct |
16 |
Correct |
62 ms |
26808 KB |
Output is correct |
17 |
Correct |
51 ms |
26112 KB |
Output is correct |
18 |
Correct |
60 ms |
27308 KB |
Output is correct |
19 |
Correct |
55 ms |
26080 KB |
Output is correct |
20 |
Correct |
50 ms |
26080 KB |
Output is correct |
21 |
Correct |
49 ms |
26188 KB |
Output is correct |
22 |
Correct |
49 ms |
26072 KB |
Output is correct |
23 |
Correct |
4 ms |
5972 KB |
Output is correct |
24 |
Correct |
3 ms |
5972 KB |
Output is correct |
25 |
Correct |
5 ms |
6100 KB |
Output is correct |
26 |
Incorrect |
4 ms |
6100 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |