#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
const int mxN = 150005;
const int inf = 2e5+5;
int N, M, A[mxN], B[mxN];
vector<int> al[mxN];
bool reach[mxN];
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int TC; cin >> TC;
while (TC--) {
cin >> N >> M;
FOR(i,1,N){ cin >> A[i]; }
FOR(i,1,N){ cin >> B[i]; }
FOR(i,1,N) al[i].clear();
FOR(i,1,M){
int U, V; cin >> U >> V;
al[U].push_back(V);
al[V].push_back(U);
}
bool ok = 1;
FOR(u,1,N) ok &= (A[u] >= B[u]);
FOR(s,1,N){
if (!ok) break;
queue<int> q;
memset(reach,0,sizeof reach);
q.push(s), reach[s] = 1;
while (!q.empty()) {
int u = q.front(); q.pop();
for (int& v : al[u]) if (!reach[v] && A[v] >= B[s] && B[v] <= B[s]) {
reach[v] = 1;
q.push(v);
}
}
bool cur = 0;
FOR(v,1,N) if (reach[v] && A[v] == B[s]) { cur = 1; break; }
ok &= cur;
}
cout << ok << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
750 ms |
4088 KB |
Output is correct |
2 |
Correct |
288 ms |
4600 KB |
Output is correct |
3 |
Correct |
38 ms |
4096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
190 ms |
4084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
754 ms |
4076 KB |
Output is correct |
2 |
Correct |
209 ms |
4600 KB |
Output is correct |
3 |
Correct |
23 ms |
4096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
754 ms |
4076 KB |
Output is correct |
2 |
Correct |
209 ms |
4600 KB |
Output is correct |
3 |
Correct |
23 ms |
4096 KB |
Output is correct |
4 |
Correct |
1339 ms |
4684 KB |
Output is correct |
5 |
Execution timed out |
3037 ms |
6776 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
750 ms |
4088 KB |
Output is correct |
2 |
Correct |
288 ms |
4600 KB |
Output is correct |
3 |
Correct |
38 ms |
4096 KB |
Output is correct |
4 |
Correct |
754 ms |
4076 KB |
Output is correct |
5 |
Correct |
209 ms |
4600 KB |
Output is correct |
6 |
Correct |
23 ms |
4096 KB |
Output is correct |
7 |
Correct |
742 ms |
4704 KB |
Output is correct |
8 |
Correct |
295 ms |
4584 KB |
Output is correct |
9 |
Correct |
77 ms |
4096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1504 ms |
4224 KB |
Output is correct |
2 |
Execution timed out |
3065 ms |
5880 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
4076 KB |
Output is correct |
2 |
Correct |
44 ms |
4352 KB |
Output is correct |
3 |
Correct |
65 ms |
4224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
750 ms |
4088 KB |
Output is correct |
2 |
Correct |
288 ms |
4600 KB |
Output is correct |
3 |
Correct |
38 ms |
4096 KB |
Output is correct |
4 |
Correct |
190 ms |
4084 KB |
Output is correct |
5 |
Correct |
754 ms |
4076 KB |
Output is correct |
6 |
Correct |
209 ms |
4600 KB |
Output is correct |
7 |
Correct |
23 ms |
4096 KB |
Output is correct |
8 |
Correct |
1339 ms |
4684 KB |
Output is correct |
9 |
Execution timed out |
3037 ms |
6776 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |