답안 #262027

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
262027 2020-08-12T09:40:02 Z errorgorn Colors (RMI18_colors) C++14
47 / 100
3000 ms 9360 KB
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n,m;
int arr[150005];
int brr[150005];
vector<int> al[150005];

bool vis[150005];

bool dfs(int i,int val){
	if (vis[i]) return false;
	vis[i]=true;
	
	if (val<brr[i] || arr[i]<val) return false;
	if (arr[i]==val) return true;
	
	for (auto &it:al[i]){
		if (dfs(it,val)) return true;
	}
	
	return false;
}

void solve(){
	cin>>n>>m;
	rep(x,1,n+1){
		al[x].clear();
	}
	
	rep(x,1,n+1) cin>>arr[x];
	rep(x,1,n+1) cin>>brr[x];
	
	int a,b;
	rep(x,0,m){
		cin>>a>>b;
		
		al[a].push_back(b);
		al[b].push_back(a);
	}
	
	rep(x,1,n+1){
		if (brr[x]>arr[x]){
			cout<<0<<endl;
			return;
		}
	}
	
	rep(x,1,n+1){
		memset(vis,false,sizeof(vis));
		if (!dfs(x,brr[x])){
			cout<<0<<endl;
			return;
		}
	}
	
	cout<<1<<endl;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int TC;
	cin>>TC;
	while (TC--){
		solve();
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 838 ms 4344 KB Output is correct
2 Correct 268 ms 4344 KB Output is correct
3 Correct 27 ms 4096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 159 ms 4304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 811 ms 4216 KB Output is correct
2 Correct 204 ms 4564 KB Output is correct
3 Correct 21 ms 4096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 811 ms 4216 KB Output is correct
2 Correct 204 ms 4564 KB Output is correct
3 Correct 21 ms 4096 KB Output is correct
4 Correct 1281 ms 7132 KB Output is correct
5 Execution timed out 3071 ms 9360 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 838 ms 4344 KB Output is correct
2 Correct 268 ms 4344 KB Output is correct
3 Correct 27 ms 4096 KB Output is correct
4 Correct 811 ms 4216 KB Output is correct
5 Correct 204 ms 4564 KB Output is correct
6 Correct 21 ms 4096 KB Output is correct
7 Correct 687 ms 5500 KB Output is correct
8 Correct 288 ms 4644 KB Output is correct
9 Correct 57 ms 4096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1415 ms 4576 KB Output is correct
2 Execution timed out 3080 ms 6144 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 97 ms 4728 KB Output is correct
2 Correct 30 ms 4352 KB Output is correct
3 Correct 38 ms 4344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 838 ms 4344 KB Output is correct
2 Correct 268 ms 4344 KB Output is correct
3 Correct 27 ms 4096 KB Output is correct
4 Correct 159 ms 4304 KB Output is correct
5 Correct 811 ms 4216 KB Output is correct
6 Correct 204 ms 4564 KB Output is correct
7 Correct 21 ms 4096 KB Output is correct
8 Correct 1281 ms 7132 KB Output is correct
9 Execution timed out 3071 ms 9360 KB Time limit exceeded
10 Halted 0 ms 0 KB -