Submission #878023

#TimeUsernameProblemLanguageResultExecution timeMemory
878023RegulusJail (JOI22_jail)C++17
21 / 100
5084 ms6848 KiB
#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], idx[N], a[N];
vector<int> g[N];

inline bool run(int x, int pre, int ed)
{
    if (a[x]) return 0;
    if (x == ed) return 1;
    bool ret = 0;
    for (int v : g[x]) if (v != pre) ret |= run(v, x, ed);
    return ret;
}

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

    cin >> T;
    do {
        cin >> n;
        for (i=1; i <= n; ++i) g[i].clear();
        for (i=0; i < n-1; ++i) cin >> x >> y, g[x].pb(y), g[y].pb(x);

        cin >> m;
        for (i=1; i <= m; ++i) cin >> s[i] >> t[i], idx[i] = i;
        ff = 0;
        do {
            for (i=1; i <= n; ++i) a[i] = 0;
            for (i=1; i <= m; ++i) a[s[i]] = 1;

            for (i=1; i <= m; ++i)
            {
                x = idx[i], a[s[x]] = 0;
                if (!run(s[x], 0, t[x])) break;
                a[t[x]] = 1;
            }
            if (i > m) ff = 1;
        } while (next_permutation(idx+1, idx+m+1));

        if (ff) cout << "Yes\n";
        else cout << "No\n";
    } while (--T);

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...