Submission #375060

#TimeUsernameProblemLanguageResultExecution timeMemory
375060ijxjdjdColors (RMI18_colors)C++14
47 / 100
3087 ms12780 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...