답안 #890900

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
890900 2023-12-22T05:03:24 Z vjudge1 Jail (JOI22_jail) C++17
0 / 100
1 ms 348 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({s, t});
        } else {
            l.push_back({s, t});
        }
        used[s] = true;
    }
    sort(all(l)), sort(all(r));
    while (!l.empty()) {
        int s = l.front().first, t = l.front().second;
        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().first, t = r.back().second;
        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();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -