# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
643129 |
2022-09-21T09:13:32 Z |
SlavicG |
Colors (RMI18_colors) |
C++17 |
|
85 ms |
2712 KB |
#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) {
if(a[i] != b[i]) nodes.push({a[i], i});
}
while(!nodes.empty()) {
int u = nodes.top().second;
nodes.pop();
int mxsmaller = -1;
for(int v: adj[u]) {
if(a[v] < a[u]) mxsmaller = max(mxsmaller, a[v]);
}
if(mxsmaller == -1) {
cout << "0\n";
return;
}
a[u] = mxsmaller;
if(a[u] != b[u]) nodes.push({a[u], u});
}
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();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
2692 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
2680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
2692 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
85 ms |
2712 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
2692 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |