Submission #877266

# Submission time Handle Problem Language Result Execution time Memory
877266 2023-11-23T05:09:01 Z Regulus Jail (JOI22_jail) C++17
0 / 100
10 ms 17584 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;
}

inline bool is_anc(int x, int y)
{
    return tin[x] <= tin[y] && tout[y] <= tout[x];
}

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[1], 0);

        if ((state[t[1]]&3) == 3)
        {
            cout << "No\n";
        } else if (state[t[1]]&2) {
            if (is_anc(t[1], s[2])) cout << "No\n";
            else cout << "Yes\n";
        } else if (state[t[1]]&1) {
            if (!is_anc(t[1], t[2])) cout << "No\n";
            else cout << "Yes\n";
        } else {
            cout << "Yes\n";
        }
    } while (--T);

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Runtime error 9 ms 17584 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Incorrect 2 ms 8792 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Incorrect 2 ms 8792 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Incorrect 2 ms 8792 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Incorrect 2 ms 8792 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Runtime error 10 ms 17500 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Runtime error 9 ms 17584 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -