Submission #261688

# Submission time Handle Problem Language Result Execution time Memory
261688 2020-08-12T01:36:48 Z oolimry Colors (RMI18_colors) C++14
7 / 100
439 ms 7012 KB
#include <bits/stdc++.h>
#define all(x) ((x).begin(), (x).end())
#define sz(x) ((int) (x).size())
using namespace std;
typedef pair<int,int> ii;

vector<int> adj[150005];
int start[150005];
int target[150005];
bool vis[150005];

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int TC; cin >> TC;
	
	while(TC--){
		
		bool die = false;
		int n, m; cin >> n >> m;
		
		for(int i = 1;i <= n;i++) adj[i].clear();
		
		for(int i = 1;i <= n;i++) cin >> start[i];
		for(int i = 1;i <= n;i++) cin >> target[i];
		
		for(int i = 1;i <= m;i++){
			int a, b; cin >> a >> b;
			adj[a].push_back(b);
			adj[b].push_back(a);
		}
		
		for(int i = 1;i <= n;i++){
			if(start[i] < target[i]){
				die = true;
				break;
			}
		}
		
		for(int C = n;C >= 1;C--){
			if(die) break;
			
			fill(vis,vis+n+1,false);
			queue<int> bfs;
			
			for(int i = 1;i <= n;i++){
				if(start[i] == C){
					vis[i] = true;
					bfs.push(i);
				}
			}
			
			while(!bfs.empty()){
				int u = bfs.front(); bfs.pop();
				for(int v : adj[u]){
					if(vis[v]) continue;
					if(target[v] > C) continue;
					bfs.push(v);
					vis[v] = true;
				}
			}
			
			for(int i = 1;i <= n;i++){
				if(target[i] == C && vis[i] == false){
					die = true;
				}
			}
		}
		
		if(die) cout << 0;
		else cout << 1;
		cout << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 146 ms 5368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 5624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 158 ms 5568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 158 ms 5568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 146 ms 5368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 439 ms 7012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 4600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 146 ms 5368 KB Output isn't correct
2 Halted 0 ms 0 KB -