답안 #375060

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
375060 2021-03-09T01:55:32 Z ijxjdjd Colors (RMI18_colors) C++14
47 / 100
3000 ms 12780 KB
#include <bits/stdc++.h>
#define FR(i, N) for (int i = 0; i < int(N); i++)
#define all(x) begin(x), end(x)

using namespace std;

using ll = long long;

const int MAXN = (int)(150000) + 5;
int N, M;

int a[MAXN];
int b[MAXN];

int par[MAXN];
int rk[MAXN];

int cur[MAXN];

pair<int, int> edges[MAXN + 50000];
vector<int> A[MAXN];
vector<int> B[MAXN];

int find(int x) {
    if (par[x] == x) {
        return x;
    }
    else {
        return find(par[x]);
    }
}
void merge(int x, int y) {
    int px = find(x);
    int py = find(y);
    if (px != py) {
        if (rk[px] < rk[py]) {
            swap(px, py);
        }
        rk[px] += rk[py];
        par[py] = px;
    }
}
void reset() {
    FR(i, N) {
        par[i] = i;
        rk[i] = 1;
        cur[i] = -1;
        A[i].clear();
        B[i].clear();
    }
}
int solve() {
    reset();
    cin >> N >> M;
    FR(i, N) {
        cin >> a[i];
        a[i]--;
        A[a[i]].push_back(i);
    }
    FR(i, N) {
        cin >> b[i];
        b[i]--;
        B[b[i]].push_back(i);
    }
    for (int i = 0; i < M; i++) {
        cin >> edges[i].first >> edges[i].second;
        edges[i].first--;
        edges[i].second--;
    }
    for (int c = 0; c < N; c++) {
        FR(i, N) {
            par[i] = i;
            rk[i] = 1;
            cur[i] = 0;
        }
        for (int j = 0; j < M; j++) {
            if (b[edges[j].first] <= c && c <= a[edges[j].first] && b[edges[j].second] <= c && c <= a[edges[j].second]) {
                merge(edges[j].first, edges[j].second);
            }
        }
        for (int ai : A[c]) {
            cur[find(ai)] = 1;
        }
        for (int bi : B[c]) {
            if (!cur[find(bi)]) {
                return 0;
            }
        }
    }
    return 1;
}
int main() {
	cin.tie(0);
	cin.sync_with_stdio(0);
    int T;
    cin >> T;
    while (T-->0) {
        cout << solve() << '\n';
    }
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 8940 KB Output is correct
2 Correct 60 ms 8044 KB Output is correct
3 Correct 35 ms 7532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 9340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 8996 KB Output is correct
2 Correct 51 ms 8064 KB Output is correct
3 Correct 23 ms 7532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 8996 KB Output is correct
2 Correct 51 ms 8064 KB Output is correct
3 Correct 23 ms 7532 KB Output is correct
4 Correct 215 ms 10604 KB Output is correct
5 Execution timed out 3087 ms 12780 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 8940 KB Output is correct
2 Correct 60 ms 8044 KB Output is correct
3 Correct 35 ms 7532 KB Output is correct
4 Correct 90 ms 8996 KB Output is correct
5 Correct 51 ms 8064 KB Output is correct
6 Correct 23 ms 7532 KB Output is correct
7 Correct 92 ms 8940 KB Output is correct
8 Correct 54 ms 8044 KB Output is correct
9 Correct 37 ms 7532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 216 ms 10556 KB Output is correct
2 Execution timed out 3059 ms 10220 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 90 ms 8172 KB Output is correct
2 Correct 76 ms 7916 KB Output is correct
3 Correct 50 ms 7788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 8940 KB Output is correct
2 Correct 60 ms 8044 KB Output is correct
3 Correct 35 ms 7532 KB Output is correct
4 Correct 167 ms 9340 KB Output is correct
5 Correct 90 ms 8996 KB Output is correct
6 Correct 51 ms 8064 KB Output is correct
7 Correct 23 ms 7532 KB Output is correct
8 Correct 215 ms 10604 KB Output is correct
9 Execution timed out 3087 ms 12780 KB Time limit exceeded
10 Halted 0 ms 0 KB -