Submission #544971

# Submission time Handle Problem Language Result Execution time Memory
544971 2022-04-03T09:04:49 Z leaked Jail (JOI22_jail) C++14
0 / 100
1 ms 344 KB
#include <bits/stdc++.h>

#define f first
#define s second
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pb push_back
#define sz(x) (int)(x).size()
#define pw(x) (1LL<<(x))
#define fast_resp ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;
typedef pair<int,ll> pil;
template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}
const int M=1e9+7;
const int N=300+1;
void add(int &a,int b){
    a+=b;
    if(a>=M) a-=M;
    else if(a<0) a+=M;
}
int mult(int a,int b){
    return 1ll*a*b%M;
}
vec<int> gr[N],g[N];
int used[N],ok;
void dfs(int v){
    used[v]=1;
    for(auto &z : gr[v]){
        if(used[z]){
            ok&=(used[z]==2);
            continue;
        }
        dfs(z);
    }
    used[v]=2;
}
int par[N],in[N],out[N],tt;
void dfs1(int v,int p){
    par[v]=p;
    in[v]=tt++;
    for(auto &z : g[v]){
        if(z==p) continue;
        dfs1(z,v);
    }
    out[v]=tt-1;
}
bool is(int a,int b){
    return in[a]<=in[b]&&out[a]>=out[b];
}
void solve(){
    int n,m;
    cin>>n;
    for(int i=0;i<n;i++) g[i].clear();
    ok=1;
    for(int i=1;i<n;i++){
        int v,u;
        cin>>v>>u;--v;--u;
        g[v].pb(u);g[u].pb(v);
    }
    dfs1(0,0);
    cin>>m;
    vec<int> st(m),f(m);
    for(int i=0;i<m;i++) used[i]=0,gr[i].clear();
    for(int i=0;i<m;i++){
        cin>>st[i]>>f[i];--st[i];--f[i];

    }
    for(int i=0;i<m;i++){
        for(int j=0;j<m;j++){
            if(i==j) continue;
            /// shoot
            int v=st[i],u=f[i];
            while(!is(v,u)){
                if(v==st[j]) gr[j].pb(i);
                if(v==f[j]) gr[i].pb(j);
                v=par[v];
            }
            v=st[i];
            swap(v,u);
            while(!is(v,u)){
                if(v==st[j]) gr[j].pb(i);
                if(v==f[j]) gr[i].pb(j);
                v=par[v];
            }
        }
    }
    for(int i=0;i<m;i++){
        if(!used[i])
            dfs(i);
    }
    cout<<(ok?"Yes":"No")<<'\n';
}
signed main(){
    fast_resp;
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
/*

*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 336 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 336 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 336 KB Output isn't correct
4 Halted 0 ms 0 KB -