# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
566913 |
2022-05-23T06:16:04 Z |
zaneyu |
Jail (JOI22_jail) |
C++14 |
|
5 ms |
9684 KB |
/*input
3
3
1 2
2 3
2
2 1
3 2
7
1 2
2 3
3 4
4 5
5 6
6 7
3
1 3
4 2
2 5
8
1 2
2 3
3 4
4 5
5 6
6 7
7 8
4
1 5
2 6
3 7
4 8
*/
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<long long,null_type,less_equal<long long>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
//order_of_key #of elements less than x
// find_by_order kth element
using ll=long long;
using ld=long double;
using pii=pair<int,int>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-6;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
out<<P.f<<' '<<P.s;
return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
REP(i,sz(V)) out<<V[i]<<((i!=sz(V)-1)?" ":"");
return out;
}
ll mult(ll a,ll b){
return a*b%MOD;
}
ll mypow(ll a,ll b){
a%=MOD;
if(a==0) return 0;
if(b<=0) return 1;
ll res=1LL;
while(b){
if(b&1) res=(res*a)%MOD;
a=(a*a)%MOD;
b>>=1;
}
return res;
}
int d;
bool hv[maxn];
bool wk=1;
vector<int> v[maxn];
int in[maxn],out[maxn];
int cur;
vector<int> vv[maxn];
bool dfs(int u,int p){
if(u==d){
return true;
}
for(int x:v[u]){
if(x==p) continue;
if(dfs(x,u)){
if(x!=d){
if(in[x]) vv[in[x]].pb(cur);
if(out[x]) vv[cur].pb(out[x]);
}
return true;
}
}
return false;
}
int vis[maxn];
void dfs2(int u){
vis[u]=1;
for(int x:vv[u]){
if(!vis[x]) dfs2(x);
else if(vis[x]==1){
wk=0;
break;
}
}
vis[u]=2;
}
void solve(){
int n,m;
cin>>n;
wk=1;
REP(i,n-1){
int a,b;
cin>>a>>b;
--a,--b;
v[a].pb(b),v[b].pb(a);
}
wk=1;
cin>>m;
vector<pii> asd;
REP1(i,m){
int a,b;
cin>>a>>b;
--a,--b;
in[a]=i,out[b]=i;
asd.pb({a,b});
}
REP(i,sz(asd)){
int a=asd[i].f,b=asd[i].s;
d=b;
cur=i+1;
dfs(a,-1);
}
REP1(i,m){
if(!vis[i]) dfs2(i);
}
if(wk){
cout<<"Yes\n";
}
else cout<<"No\n";
REP(i,n) v[i].clear(),hv[i]=in[i]=out[i]=0;
REP1(i,m) vv[i].clear(),vis[i]=0;
}
int main(){
int t;
cin>>t;
while(t--) solve();
}
Compilation message
jail.cpp: In function 'void solve()':
jail.cpp:159:38: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
159 | REP(i,n) v[i].clear(),hv[i]=in[i]=out[i]=0;
| ~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Incorrect |
5 ms |
9684 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Incorrect |
5 ms |
9632 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Incorrect |
5 ms |
9632 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Incorrect |
5 ms |
9632 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Incorrect |
5 ms |
9632 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Incorrect |
5 ms |
9684 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Incorrect |
5 ms |
9684 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |