Submission #261689

# Submission time Handle Problem Language Result Execution time Memory
261689 2020-08-12T01:40:50 Z oolimry Colors (RMI18_colors) C++14
47 / 100
3000 ms 7036 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 || start[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 Correct 117 ms 3840 KB Output is correct
2 Correct 60 ms 4480 KB Output is correct
3 Correct 27 ms 3968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 3840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 3840 KB Output is correct
2 Correct 58 ms 4472 KB Output is correct
3 Correct 21 ms 3968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 3840 KB Output is correct
2 Correct 58 ms 4472 KB Output is correct
3 Correct 21 ms 3968 KB Output is correct
4 Correct 249 ms 7036 KB Output is correct
5 Execution timed out 3092 ms 6392 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 117 ms 3840 KB Output is correct
2 Correct 60 ms 4480 KB Output is correct
3 Correct 27 ms 3968 KB Output is correct
4 Correct 111 ms 3840 KB Output is correct
5 Correct 58 ms 4472 KB Output is correct
6 Correct 21 ms 3968 KB Output is correct
7 Correct 120 ms 5368 KB Output is correct
8 Correct 59 ms 4472 KB Output is correct
9 Correct 29 ms 3968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 256 ms 4104 KB Output is correct
2 Execution timed out 3075 ms 5888 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 50 ms 3840 KB Output is correct
2 Correct 28 ms 4176 KB Output is correct
3 Correct 33 ms 4088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 117 ms 3840 KB Output is correct
2 Correct 60 ms 4480 KB Output is correct
3 Correct 27 ms 3968 KB Output is correct
4 Correct 98 ms 3840 KB Output is correct
5 Correct 111 ms 3840 KB Output is correct
6 Correct 58 ms 4472 KB Output is correct
7 Correct 21 ms 3968 KB Output is correct
8 Correct 249 ms 7036 KB Output is correct
9 Execution timed out 3092 ms 6392 KB Time limit exceeded
10 Halted 0 ms 0 KB -