답안 #443245

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
443245 2021-07-10T08:38:41 Z valerikk Colors (RMI18_colors) C++17
47 / 100
3000 ms 7384 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1.5e5 + 123;

int n, m;
int a[N], b[N];
vector<int> g[N];
bool used[N], f[N];

bool solve() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n; i++) g[i].clear();
    while (m--) {
        int v, u;
        cin >> v >> u;
        v--, u--;
        g[v].push_back(u);
        g[u].push_back(v);
    }
    for (int i = 0; i < n; i++) {
        if (a[i] < b[i]) return 0;
    }
    for (int i = 0; i < n; i++) f[i] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) used[j] = 0;
        used[i] = 1;
        queue<int> q;
        q.push(i);
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            for (int u : g[v]) {
                if (!used[u] && a[u] >= a[i] && b[u] <= a[i]) {
                    used[u] = 1;
                    q.push(u);
                }
            }
        }
        for (int j = 0; j < n; j++) {
            if (used[j] && b[j] == a[i]) f[j] = 1;
        }
    }
    for (int i = 0; i < n; i++) {
        if (!f[i]) return 0;
    }
    return 1;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        cout << (solve() ? "1" : "0") << "\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 5264 KB Output is correct
2 Correct 50 ms 4372 KB Output is correct
3 Correct 28 ms 3976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 5572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 5244 KB Output is correct
2 Correct 34 ms 4420 KB Output is correct
3 Correct 9 ms 3916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 5244 KB Output is correct
2 Correct 34 ms 4420 KB Output is correct
3 Correct 9 ms 3916 KB Output is correct
4 Correct 164 ms 6904 KB Output is correct
5 Execution timed out 3054 ms 7384 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 5264 KB Output is correct
2 Correct 50 ms 4372 KB Output is correct
3 Correct 28 ms 3976 KB Output is correct
4 Correct 81 ms 5244 KB Output is correct
5 Correct 34 ms 4420 KB Output is correct
6 Correct 9 ms 3916 KB Output is correct
7 Correct 92 ms 5388 KB Output is correct
8 Correct 45 ms 4372 KB Output is correct
9 Correct 25 ms 3916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 199 ms 6968 KB Output is correct
2 Execution timed out 3074 ms 5784 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 4548 KB Output is correct
2 Correct 30 ms 4224 KB Output is correct
3 Correct 43 ms 3916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 5264 KB Output is correct
2 Correct 50 ms 4372 KB Output is correct
3 Correct 28 ms 3976 KB Output is correct
4 Correct 101 ms 5572 KB Output is correct
5 Correct 81 ms 5244 KB Output is correct
6 Correct 34 ms 4420 KB Output is correct
7 Correct 9 ms 3916 KB Output is correct
8 Correct 164 ms 6904 KB Output is correct
9 Execution timed out 3054 ms 7384 KB Time limit exceeded
10 Halted 0 ms 0 KB -