Submission #557853

# Submission time Handle Problem Language Result Execution time Memory
557853 2022-05-06T07:18:41 Z FatihSolak Colors (RMI18_colors) C++17
22 / 100
192 ms 19332 KB
#include <bits/stdc++.h>
#define N 200005
using namespace std;
int a[N];
int b[N];
vector<int> adj[N];
set<int> s[N];
vector<int> v[N];
int par[N];
int find(int a){
	if(a == par[a])return a;
	return par[a] = find(par[a]);
}
void merge(int a,int b){
	a = find(a);
	b = find(b);
	if(a == b)return;
	if(s[a].size() > s[b].size())
		swap(s[a],s[b]);
	for(auto u:s[a])
		s[b].insert(u);
	s[a].clear();
	par[a] = b;
}
void solve(){
	int n,m;
	cin >> n >> m;
	for(int i = 1;i<=n;i++){
		cin >> a[i];
		adj[i].clear();
		par[i] = i;
		s[i] = {a[i]};
		v[i].clear();
	}
	for(int i = 1;i<=n;i++){
		cin >> b[i];
		v[b[i]].push_back(i);
	}
	for(int i = 1;i<=m;i++){
		int u,v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
		if(a[v] >= b[u] && a[u] >= a[v])
			s[u].insert(a[v]);
		if(a[u] >= b[v] && a[v] >= a[u])
			s[v].insert(a[u]);
	}
	for(int i = 1;i<=n;i++){
		if(a[i] < b[i]){
			cout << 0 << endl;
			return;
		}
	}
	for(int i = 1;i<=n;i++){
		if(v[i].empty())continue;
		for(auto u:v[i]){
			for(auto c:adj[u]){
				if(b[c] <= b[u] && a[c]>=i){
					merge(u,c);
				}
			}
		}
		for(auto u:v[i]){
			//cout << u << " " << find(u) << endl;
			if(s[find(u)].count(i) == 0){
				cout << 0 << endl;
				return;
			}
		}
	}
	cout << 1 << endl;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	#ifdef Local
		freopen("in.txt","r",stdin);
		freopen("out.txt","w",stdout);
	#endif
	int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
	#ifdef Local
		cout << endl << fixed << setprecision(2) << 1000.0*clock()/CLOCKS_PER_SEC << " milliseconds.";
	#endif
}
# Verdict Execution time Memory Grader output
1 Correct 100 ms 19156 KB Output is correct
2 Correct 34 ms 19192 KB Output is correct
3 Correct 12 ms 19332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 19328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 84 ms 19144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 84 ms 19144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 100 ms 19156 KB Output is correct
2 Correct 34 ms 19192 KB Output is correct
3 Correct 12 ms 19332 KB Output is correct
4 Incorrect 84 ms 19144 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 192 ms 19284 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 19156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 100 ms 19156 KB Output is correct
2 Correct 34 ms 19192 KB Output is correct
3 Correct 12 ms 19332 KB Output is correct
4 Correct 78 ms 19328 KB Output is correct
5 Incorrect 84 ms 19144 KB Output isn't correct
6 Halted 0 ms 0 KB -