#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define forn(i, n) for(int i = 0; i < n; ++i)
const int N = 1e5 + 10;
vector<int> adj[N];
int a[N], b[N];
void solve() {
int n, m; cin >> n >> m;
forn(i, n) adj[i].clear();
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 < m; ++i) {
int u, v; cin >> u >> v; --u, --v;
adj[u].pb(v);
adj[v].pb(u);
}
priority_queue<pair<int, int>> nodes;
for(int i = 0; i < n; ++i) {
nodes.push({a[i], i});
}
set<pair<int, int>> vis;
while(!nodes.empty()) {
int u = nodes.top().second;
nodes.pop();
if(vis.count({a[u], u})) continue;
vis.insert({a[u], u});
for(int v: adj[u]) {
if(a[v] != b[v] && a[v] > a[u]) {
a[v] = a[u];
nodes.push({a[v], v});
}
}
}
forn(i, n) {
if(a[i] != b[i]) {
cout << "0\n";
return;
}
}
cout << "1\n";
}
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t; cin >> t;
while(t--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
264 ms |
2756 KB |
Output is correct |
2 |
Correct |
268 ms |
3040 KB |
Output is correct |
3 |
Correct |
267 ms |
15944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
2760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
2840 KB |
Output is correct |
2 |
Correct |
48 ms |
2712 KB |
Output is correct |
3 |
Correct |
9 ms |
3028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
2840 KB |
Output is correct |
2 |
Correct |
48 ms |
2712 KB |
Output is correct |
3 |
Correct |
9 ms |
3028 KB |
Output is correct |
4 |
Correct |
251 ms |
2696 KB |
Output is correct |
5 |
Execution timed out |
3103 ms |
356540 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
264 ms |
2756 KB |
Output is correct |
2 |
Correct |
268 ms |
3040 KB |
Output is correct |
3 |
Correct |
267 ms |
15944 KB |
Output is correct |
4 |
Correct |
114 ms |
2840 KB |
Output is correct |
5 |
Correct |
48 ms |
2712 KB |
Output is correct |
6 |
Correct |
9 ms |
3028 KB |
Output is correct |
7 |
Correct |
199 ms |
2868 KB |
Output is correct |
8 |
Correct |
160 ms |
3028 KB |
Output is correct |
9 |
Correct |
243 ms |
15308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
601 ms |
2968 KB |
Output is correct |
2 |
Execution timed out |
3089 ms |
339244 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
2748 KB |
Output is correct |
2 |
Correct |
34 ms |
3032 KB |
Output is correct |
3 |
Correct |
184 ms |
6888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
264 ms |
2756 KB |
Output is correct |
2 |
Correct |
268 ms |
3040 KB |
Output is correct |
3 |
Correct |
267 ms |
15944 KB |
Output is correct |
4 |
Correct |
86 ms |
2760 KB |
Output is correct |
5 |
Correct |
114 ms |
2840 KB |
Output is correct |
6 |
Correct |
48 ms |
2712 KB |
Output is correct |
7 |
Correct |
9 ms |
3028 KB |
Output is correct |
8 |
Correct |
251 ms |
2696 KB |
Output is correct |
9 |
Execution timed out |
3103 ms |
356540 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |