답안 #941790

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
941790 2024-03-09T12:16:23 Z KiaRez Colors (RMI18_colors) C++17
47 / 100
3000 ms 15492 KB
/*
    IN THE NAME OF GOD
*/
#include <bits/stdc++.h>

// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;

#define F                                      first
#define S                                      second
#define Mp                                     make_pair
#define pb                                     push_back
#define pf                                     push_front
#define size(x)                                ((ll)x.size())
#define all(x)                                 (x).begin(),(x).end()
#define kill(x)		                           cout << x << '\n', exit(0);
#define fuck(x)                                cout << "(" << #x << " , " << x << ")" << endl
#define endl                                   '\n'

const int N = 3e5+23, lg = 18;
ll Mod = 1e9+7; //998244353;

inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
    ll ans = 1;
    a=MOD(a, mod);
    while (b) {
        if (b & 1) ans = MOD(ans*a, mod);
        b >>= 1;
        a = MOD(a*a, mod);
    }
    return ans;
}

int t, n, m, a[N], b[N], mark[N], vis[N];
vector<int> adj[N];

void check(int v) {
	queue<int> q; q.push(v);
	fill(mark, mark+n+2, 0);
	mark[v] = 1;

	while(size(q) > 0) {
		int u = q.front(); 
		q.pop();
		if(a[v] == b[u]) vis[u] = 1;
		for(auto w : adj[u]) {
			if(mark[w] == 0 && a[v]<=a[w] && a[v]>=b[w]) {
				mark[w] = 1; q.push(w);
			}
		}
	}
}

void solve() {
	cin>>n>>m;
	for(int i=1; i<=n; i++) cin>>a[i];
	for(int i=1; i<=n; i++) cin>>b[i];

	for(int v,u,i=1; i<=m; i++) {
		cin>>v>>u;
		adj[v].pb(u); adj[u].pb(v);
	}

	for(int i=1; i<=n; i++) {
		check(i);
	}
	for(int i=1; i<=n; i++) if(vis[i] == 0) {
		cout<<0<<endl; return;
	}
	cout<<1<<endl;
}

void reset() {
	for(int i=1; i<=n; i++) {
		adj[i].clear();
		mark[i] = vis[i] = a[i] = b[i] = 0;
	}
}

int main () {
	ios_base::sync_with_stdio(false), cin.tie(0);

	cin>>t;
	while(t--) {
		solve();
		reset();
	}

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 12292 KB Output is correct
2 Correct 25 ms 11352 KB Output is correct
3 Correct 14 ms 10844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 12372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 12372 KB Output is correct
2 Correct 17 ms 11612 KB Output is correct
3 Correct 4 ms 10844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 12372 KB Output is correct
2 Correct 17 ms 11612 KB Output is correct
3 Correct 4 ms 10844 KB Output is correct
4 Correct 80 ms 13960 KB Output is correct
5 Execution timed out 3066 ms 15492 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 12292 KB Output is correct
2 Correct 25 ms 11352 KB Output is correct
3 Correct 14 ms 10844 KB Output is correct
4 Correct 41 ms 12372 KB Output is correct
5 Correct 17 ms 11612 KB Output is correct
6 Correct 4 ms 10844 KB Output is correct
7 Correct 50 ms 12368 KB Output is correct
8 Correct 23 ms 11356 KB Output is correct
9 Correct 12 ms 11020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 108 ms 14112 KB Output is correct
2 Execution timed out 3094 ms 14164 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 11672 KB Output is correct
2 Correct 21 ms 11100 KB Output is correct
3 Correct 29 ms 10840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 12292 KB Output is correct
2 Correct 25 ms 11352 KB Output is correct
3 Correct 14 ms 10844 KB Output is correct
4 Correct 66 ms 12372 KB Output is correct
5 Correct 41 ms 12372 KB Output is correct
6 Correct 17 ms 11612 KB Output is correct
7 Correct 4 ms 10844 KB Output is correct
8 Correct 80 ms 13960 KB Output is correct
9 Execution timed out 3066 ms 15492 KB Time limit exceeded
10 Halted 0 ms 0 KB -