This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |