Submission #1001113

# Submission time Handle Problem Language Result Execution time Memory
1001113 2024-06-18T14:51:03 Z De3b0o Jail (JOI22_jail) C++14
0 / 100
10 ms 14752 KB
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define in insert
#define pb push_back
#define ppb pop_back()
#define d3 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cans cout << ans << "\n";
#define yes cout << "Yes" << "\n";
#define no cout << "No" << "\n";
#define pll pair<ll,ll>
#define lin cout << "\n";
#define mod 1000000007
#define mid ((l+r)/2)
#define lc (2*x)
#define rc (2*x+1)

using namespace std;

ll n , m;
vector<ll> adj[120009];
ll S[120009] , T[120009];
vector<ll> path[120009];
set<ll> pas[120009];
ll pr[120009];

void dfs(ll x , ll p , ll f , ll s)
{
    pr[x]=p;
    if(x==f)
    {
        ll y = f;
        while(y)
        {
            path[s].pb(y);
            pas[s].in(y);
            y=pr[y];
        }
        reverse(path[s].begin(),path[s].end());
        return;
    }
    for(auto it : adj[x])
    {
        if(it==p)
            continue;
        dfs(it,x,f,s);
    }
}

int main()
{
    d3
    ll t;
    cin >> t;
    while(t--)
    {
        cin >> n;
        for(int i = 1 ; n>=i ; i++)
            adj[i].clear();
        for(int i = 0 ; n-1>i ; i++)
        {
            ll u , v;
            cin >> u >> v;
            adj[u].pb(v);
            adj[v].pb(u);
        }
        cin >> m;
        for(int i = 1 ; m>=i ; i++)
        {
            cin >> S[i] >> T[i];
            path[i].clear();
            pas[i].clear();
            dfs(S[i],0,T[i],i);
        }
        bool ans = 1;
        for(int i = 1 ; m>=i ; i++)
        {
            for(int j = 1 ; m>=j ; j++)
            {
                if(i==j)
                    continue;
                if(pas[i].find(S[j])!=pas[i].end()&&pas[j].find(S[i])!=pas[j].end())
                    ans=0;
                bool l = 1;
                for(auto it : path[i])
                {
                    if(pas[j].find(it)==pas[j].end())
                        l=0;
                }
                if(l)
                    ans=0;
            }
        }
        if(ans)
            yes
        else
            no
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14168 KB Output is correct
2 Correct 2 ms 14172 KB Output is correct
3 Correct 2 ms 14344 KB Output is correct
4 Incorrect 10 ms 14752 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14376 KB Output is correct
2 Correct 2 ms 14376 KB Output is correct
3 Incorrect 3 ms 14428 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14376 KB Output is correct
2 Correct 2 ms 14376 KB Output is correct
3 Incorrect 3 ms 14428 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14376 KB Output is correct
2 Correct 2 ms 14376 KB Output is correct
3 Incorrect 3 ms 14428 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14376 KB Output is correct
2 Correct 2 ms 14376 KB Output is correct
3 Incorrect 3 ms 14428 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14168 KB Output is correct
2 Incorrect 2 ms 14172 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 14168 KB Output is correct
2 Correct 2 ms 14172 KB Output is correct
3 Correct 2 ms 14344 KB Output is correct
4 Incorrect 10 ms 14752 KB Output isn't correct
5 Halted 0 ms 0 KB -