# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
694022 |
2023-02-03T14:59:50 Z |
4EVER |
Jail (JOI22_jail) |
C++11 |
|
309 ms |
10068 KB |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define PB push_back
#define ALL(i_) i_.begin(), i_.end()
#define LOG2(x_) (31 - __builtin_clz(x_))
#define getBit(x_, i_) ((x_ >> i_) & (ll) 1)
#define rd(l_, r_) (l_ + rng() % (r_ - l_ + 1))
#define FOR(i_, a_, b_) for(int i_ = (int) (a_); i_ <= (int) (b_); ++i_)
#define FORD(i_, a_, b_) for(int i_ = (int) (a_); i_ >= (int) (b_); --i_)
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef DEBUG
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
typedef long long ll;
typedef long double ld;
template<class X, class Y> bool minimize(X &x, const Y &y){
X eps = 1e-9;
if (x > y + eps) {
x = y;
return 1;
}
return 0;
}
template<class X, class Y> bool maximize(X &x, const Y &y) {
X eps = 1e-9;
if (x + eps < y) {
x = y;
return 1;
}
return 0;
}
template<class T> T Abs(const T &x) { return (x < 0 ? -x : x); }
template<class T> using heap_min = priority_queue<T, vector<T>, greater<T>>;
template<class T> using heap_max = priority_queue<T>;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> OST;
const int mod = (int) 1e9 + 7; // 998244353
const int oo = (int) 1e9 + 99;
const array<int, 2> dxy8[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1}, {1, -1}, {1, 1}, {-1, 1}, {-1, -1} };
const array<int, 2> dxy4[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
const int maxn = (int) 1e5 + 11;
const int LOG = (int) LOG2(maxn) + 3;
void File(){
#define TASK "JAIL"
if(fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
}
int n, m;
vector<int> adj[maxn];
int s[maxn], t[maxn];
void ReadInput(){
cin >> n;
FOR(i, 1, n) adj[i].clear();
FOR(i, 1, n - 1){
int u, v; cin >> u >> v;
adj[u].PB(v);
adj[v].PB(u);
}
cin >> m;
FOR(i, 1, m) cin >> s[i] >> t[i];
}
int cnt;
int depth[maxn], tin[maxn], tout[maxn];
int spt[LOG + 3][maxn];
void DFS(int u = 1, int par = -1){
tin[u] = ++cnt;
for(int v : adj[u]) if(v != par){
depth[v] = depth[u] + 1;
spt[0][v] = u;
FOR(i, 1, LOG) spt[i][v] = spt[i - 1][spt[i - 1][v]];
DFS(v, u);
}
tout[u] = cnt;
}
int LCA(int u, int v){
if(depth[u] < depth[v]) swap(u, v);
int k = depth[u] - depth[v];
FORD(i, LOG, 0) if(getBit(k, i)) u = spt[i][u];
if(u == v) return u;
FORD(i, LOG, 0) if(spt[i][u] != spt[i][v]){
u = spt[i][u];
v = spt[i][v];
}
return spt[0][u];
}
bool Anc(int v, int u){
return (tin[u] <= tin[v] && tout[v] <= tout[u]);
}
bool Inpath(int x, int u, int v){
if(!Anc(x, LCA(u, v))) return 0;
return Anc(u, x) || Anc(v, x);
}
vector<int> ke[maxn];
int deg[maxn];
void Solve(){
cnt = 0;
DFS();
FOR(i, 1, m){
deg[i] = 0;
ke[i].clear();
}
FOR(i, 1, m){
FOR(j, 1, m) if(i != j){
if(Inpath(s[j], s[i], t[i])){
ke[j].PB(i);
++deg[i];
}
if(Inpath(t[j], s[i], t[i])){
ke[i].PB(j);
++deg[j];
}
}
}
queue<int> que;
FOR(i, 1, m) if(!deg[i]) que.push(i);
while(!que.empty()){
int u = que.front(); que.pop();
for(int v : ke[u]){
--deg[v];
if(!deg[v]) que.push(v);
}
}
int res = 1;
FOR(i, 1, m) res &= (deg[i] == 0);
cout << (res ? "Yes\n" : "No\n");
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
File();
int ntest; cin >> ntest;
while(ntest--){
ReadInput();
Solve();
}
cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
return 0;
}
Compilation message
jail.cpp: In function 'void File()':
jail.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
82 | freopen(TASK".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
jail.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
83 | freopen(TASK".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5040 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
11 ms |
5428 KB |
Output is correct |
5 |
Correct |
26 ms |
5964 KB |
Output is correct |
6 |
Correct |
4 ms |
5200 KB |
Output is correct |
7 |
Correct |
5 ms |
5176 KB |
Output is correct |
8 |
Correct |
17 ms |
5268 KB |
Output is correct |
9 |
Correct |
279 ms |
9384 KB |
Output is correct |
10 |
Runtime error |
8 ms |
10068 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
4 ms |
5172 KB |
Output is correct |
6 |
Correct |
4 ms |
5184 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
4 ms |
5204 KB |
Output is correct |
10 |
Correct |
4 ms |
5176 KB |
Output is correct |
11 |
Correct |
4 ms |
5204 KB |
Output is correct |
12 |
Correct |
3 ms |
5076 KB |
Output is correct |
13 |
Correct |
4 ms |
5176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
4 ms |
5172 KB |
Output is correct |
6 |
Correct |
4 ms |
5184 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
4 ms |
5204 KB |
Output is correct |
10 |
Correct |
4 ms |
5176 KB |
Output is correct |
11 |
Correct |
4 ms |
5204 KB |
Output is correct |
12 |
Correct |
3 ms |
5076 KB |
Output is correct |
13 |
Correct |
4 ms |
5176 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
5036 KB |
Output is correct |
16 |
Correct |
4 ms |
5204 KB |
Output is correct |
17 |
Correct |
5 ms |
5076 KB |
Output is correct |
18 |
Correct |
4 ms |
5076 KB |
Output is correct |
19 |
Correct |
3 ms |
5044 KB |
Output is correct |
20 |
Correct |
4 ms |
5072 KB |
Output is correct |
21 |
Correct |
4 ms |
5204 KB |
Output is correct |
22 |
Correct |
4 ms |
5200 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
3 ms |
5040 KB |
Output is correct |
25 |
Correct |
4 ms |
5176 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
4 ms |
5176 KB |
Output is correct |
28 |
Correct |
4 ms |
5036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
4 ms |
5172 KB |
Output is correct |
6 |
Correct |
4 ms |
5184 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
4 ms |
5204 KB |
Output is correct |
10 |
Correct |
4 ms |
5176 KB |
Output is correct |
11 |
Correct |
4 ms |
5204 KB |
Output is correct |
12 |
Correct |
3 ms |
5076 KB |
Output is correct |
13 |
Correct |
4 ms |
5176 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
5036 KB |
Output is correct |
16 |
Correct |
4 ms |
5204 KB |
Output is correct |
17 |
Correct |
5 ms |
5076 KB |
Output is correct |
18 |
Correct |
4 ms |
5076 KB |
Output is correct |
19 |
Correct |
3 ms |
5044 KB |
Output is correct |
20 |
Correct |
4 ms |
5072 KB |
Output is correct |
21 |
Correct |
4 ms |
5204 KB |
Output is correct |
22 |
Correct |
4 ms |
5200 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
3 ms |
5040 KB |
Output is correct |
25 |
Correct |
4 ms |
5176 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
4 ms |
5176 KB |
Output is correct |
28 |
Correct |
4 ms |
5036 KB |
Output is correct |
29 |
Correct |
15 ms |
5300 KB |
Output is correct |
30 |
Correct |
13 ms |
5176 KB |
Output is correct |
31 |
Correct |
11 ms |
5204 KB |
Output is correct |
32 |
Correct |
8 ms |
5116 KB |
Output is correct |
33 |
Correct |
4 ms |
5204 KB |
Output is correct |
34 |
Correct |
25 ms |
5204 KB |
Output is correct |
35 |
Correct |
23 ms |
5256 KB |
Output is correct |
36 |
Correct |
27 ms |
5196 KB |
Output is correct |
37 |
Correct |
16 ms |
5204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
4 ms |
5076 KB |
Output is correct |
5 |
Correct |
4 ms |
5172 KB |
Output is correct |
6 |
Correct |
4 ms |
5184 KB |
Output is correct |
7 |
Correct |
3 ms |
5076 KB |
Output is correct |
8 |
Correct |
4 ms |
5076 KB |
Output is correct |
9 |
Correct |
4 ms |
5204 KB |
Output is correct |
10 |
Correct |
4 ms |
5176 KB |
Output is correct |
11 |
Correct |
4 ms |
5204 KB |
Output is correct |
12 |
Correct |
3 ms |
5076 KB |
Output is correct |
13 |
Correct |
4 ms |
5176 KB |
Output is correct |
14 |
Correct |
3 ms |
5076 KB |
Output is correct |
15 |
Correct |
3 ms |
5036 KB |
Output is correct |
16 |
Correct |
4 ms |
5204 KB |
Output is correct |
17 |
Correct |
5 ms |
5076 KB |
Output is correct |
18 |
Correct |
4 ms |
5076 KB |
Output is correct |
19 |
Correct |
3 ms |
5044 KB |
Output is correct |
20 |
Correct |
4 ms |
5072 KB |
Output is correct |
21 |
Correct |
4 ms |
5204 KB |
Output is correct |
22 |
Correct |
4 ms |
5200 KB |
Output is correct |
23 |
Correct |
3 ms |
5076 KB |
Output is correct |
24 |
Correct |
3 ms |
5040 KB |
Output is correct |
25 |
Correct |
4 ms |
5176 KB |
Output is correct |
26 |
Correct |
3 ms |
5076 KB |
Output is correct |
27 |
Correct |
4 ms |
5176 KB |
Output is correct |
28 |
Correct |
4 ms |
5036 KB |
Output is correct |
29 |
Correct |
15 ms |
5300 KB |
Output is correct |
30 |
Correct |
13 ms |
5176 KB |
Output is correct |
31 |
Correct |
11 ms |
5204 KB |
Output is correct |
32 |
Correct |
8 ms |
5116 KB |
Output is correct |
33 |
Correct |
4 ms |
5204 KB |
Output is correct |
34 |
Correct |
25 ms |
5204 KB |
Output is correct |
35 |
Correct |
23 ms |
5256 KB |
Output is correct |
36 |
Correct |
27 ms |
5196 KB |
Output is correct |
37 |
Correct |
16 ms |
5204 KB |
Output is correct |
38 |
Correct |
309 ms |
9300 KB |
Output is correct |
39 |
Runtime error |
7 ms |
9960 KB |
Execution killed with signal 11 |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
3 ms |
5036 KB |
Output is correct |
5 |
Correct |
11 ms |
5264 KB |
Output is correct |
6 |
Correct |
4 ms |
5076 KB |
Output is correct |
7 |
Correct |
3 ms |
5172 KB |
Output is correct |
8 |
Correct |
3 ms |
5076 KB |
Output is correct |
9 |
Correct |
3 ms |
5032 KB |
Output is correct |
10 |
Correct |
3 ms |
5076 KB |
Output is correct |
11 |
Correct |
3 ms |
5076 KB |
Output is correct |
12 |
Correct |
25 ms |
5200 KB |
Output is correct |
13 |
Correct |
213 ms |
5724 KB |
Output is correct |
14 |
Correct |
111 ms |
6008 KB |
Output is correct |
15 |
Correct |
178 ms |
5900 KB |
Output is correct |
16 |
Runtime error |
8 ms |
10024 KB |
Execution killed with signal 11 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5076 KB |
Output is correct |
2 |
Correct |
3 ms |
5040 KB |
Output is correct |
3 |
Correct |
3 ms |
5076 KB |
Output is correct |
4 |
Correct |
11 ms |
5428 KB |
Output is correct |
5 |
Correct |
26 ms |
5964 KB |
Output is correct |
6 |
Correct |
4 ms |
5200 KB |
Output is correct |
7 |
Correct |
5 ms |
5176 KB |
Output is correct |
8 |
Correct |
17 ms |
5268 KB |
Output is correct |
9 |
Correct |
279 ms |
9384 KB |
Output is correct |
10 |
Runtime error |
8 ms |
10068 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |