Submission #890889

# Submission time Handle Problem Language Result Execution time Memory
890889 2023-12-22T04:55:57 Z vjudge1 Jail (JOI22_jail) C++17
0 / 100
1 ms 496 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define size(x) (int)x.size()

template<class S, class T>
bool chmin(S &a, const T &b) {
    return a > b && (a = b) == b;
}
template<class S, class T>
bool chmax(S &a, const T &b) {
    return a < b && (a = b) == b;
}
const int inf = 1e9 + 7;
const int INF = 1e18 + 7;
const int mod = 998244353;

void Main() {
    int n;
    cin >> n;
    for (int i = 1; i < n; ++i) {
        int a, b;
        cin >> a >> b;
    }
    vector<bool> used(n, false);
    bool flag = true;
    deque<pair<int, int>> l, r;
    int m;
    cin >> m;
    while (m--) {
        int s, t;
        cin >> s >> t;
        s--, t--;
        if (t > s) {
            r.push_back({t, s});
        } else {
            l.push_back({t, s});
        }
        used[s] = true;
    }
    sort(all(l)), sort(all(r));
    while (!l.empty()) {
        int s = l.front().second, t = l.front().first;
        l.pop_front();
        used[s] = false;
        while (s > t) {
            if (used[s]) {
                flag = false;
                break;
            }
            s--;
        }
        used[t] = true;
    }
    while (!r.empty()) {
        int s = r.back().second, t = r.back().first;
        r.pop_back();
        used[s] = false;
        while (s < t) {
            if (used[s]) {
                flag = false;
                break;
            }
            s++;
        }
        used[t] = true;
    }
    cout << (flag ? "Yes" : "No") << '\n';
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int q;
    cin >> q;
    while (q--) {
        Main();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 496 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -