답안 #890924

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
890924 2023-12-22T05:17:09 Z vjudge1 Jail (JOI22_jail) C++17
5 / 100
2599 ms 2396 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();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
5 Correct 10 ms 456 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 18 ms 348 KB Output is correct
10 Correct 56 ms 344 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 15 ms 348 KB Output is correct
13 Correct 25 ms 1116 KB Output is correct
14 Correct 29 ms 1116 KB Output is correct
15 Correct 23 ms 1112 KB Output is correct
16 Correct 39 ms 2392 KB Output is correct
17 Correct 2599 ms 1440 KB Output is correct
18 Correct 30 ms 2396 KB Output is correct
19 Correct 883 ms 1436 KB Output is correct
20 Correct 882 ms 1436 KB Output is correct
21 Correct 22 ms 1368 KB Output is correct
22 Correct 21 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 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 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 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 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 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 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 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 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 3 ms 344 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 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 Correct 0 ms 348 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
5 Correct 10 ms 456 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 18 ms 348 KB Output is correct
10 Correct 56 ms 344 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 15 ms 348 KB Output is correct
13 Correct 25 ms 1116 KB Output is correct
14 Correct 29 ms 1116 KB Output is correct
15 Correct 23 ms 1112 KB Output is correct
16 Correct 39 ms 2392 KB Output is correct
17 Correct 2599 ms 1440 KB Output is correct
18 Correct 30 ms 2396 KB Output is correct
19 Correct 883 ms 1436 KB Output is correct
20 Correct 882 ms 1436 KB Output is correct
21 Correct 22 ms 1368 KB Output is correct
22 Correct 21 ms 1372 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Incorrect 1 ms 348 KB Output isn't correct
27 Halted 0 ms 0 KB -