Submission #877247

# Submission time Handle Problem Language Result Execution time Memory
877247 2023-11-23T04:53:56 Z Regulus Jail (JOI22_jail) C++17
0 / 100
2 ms 8796 KB
#include <bits/stdc++.h>            // pA
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define debug(x) cerr << #x << " = " << (x) << ' '
#define endl cerr << '\n'
#define all(v) (v).begin(), (v).end()
#define SZ(v) (ll)(v).size()
#define lowbit(x) (x)&-(x)
#define pb emplace_back
#define F first
#define S second
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

const int N = 2e5+5;
//const int INF = 2e9;
int s[N], t[N], state[N], tin[N], sz[N], timer, tout[N];
vector<int> g[N];

inline void dfs(int x, int pre)
{
    tin[x] = ++timer, sz[x] = 1;
    for (int v : g[x])
    {
        if (v == pre) continue;
        state[v] |= state[x];
        dfs(v, x);
        sz[x] += sz[v];
    }
    tout[x] = ++timer;
}

int main(void)
{ IO
    ll T, n, i, m, x, y;

    cin >> T;
    do {
        cin >> n;
        for (i=1; i <= n; ++i) tin[i] = tout[i] = sz[i] = state[i] = 0, g[i].clear();
        for (i=0; i < n-1; ++i) cin >> x >> y, g[x].pb(y), g[y].pb(x);
        
        cin >> m;
        if (m != 2) assert(0);
        for (i=1; i <= m; ++i) cin >> s[i] >> t[i];

        state[s[2]] |= 1, state[t[2]] |= 2;
        timer = 0;
        dfs(s[i], 0);

        if (state[t[1]]&2) cout << "No\n";
        else if (state[t[1]]&1) {
            if (tin[t[1]] <= tin[t[2]] && tout[t[2]] <= tin[t[1]]) cout << "No\n";
            else cout << "Yes\n";
        } else {
            cout << "Yes\n";
        }
    } while (--T);

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 8796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 8792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 8796 KB Output isn't correct
2 Halted 0 ms 0 KB -