답안 #851766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
851766 2023-09-20T14:49:40 Z TimDee Colors (RMI18_colors) C++17
7 / 100
158 ms 9808 KB
//  Esti <3

//\
     šťastia pre nás :)
//   you're already the best
//             _
//   ^ ^      //
// >(O_O)<___//
//   \ __ __  \
//    \\ \\ \\\\
 
#include <bits/stdc++.h>
using namespace std;
 
//#pragma GCC optimize("O3","unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
 
#pragma GCC optimize("O3")
#pragma GCC target("popcnt")

using ll = long long;
#define int long long
#define forn(i,n) for(int i=0; i<(n); ++i)
#define pb push_back
#define pi pair<int,int>
#define f first
#define s second 
#define vii(a,n) vector<int> a(n); forn(i,n) cin>>a[i];
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
 
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e18;
const int mod = 998244353;
 
// \
\
:smiling_face_with_3_hearts: :smiling_face_with_3_hearts:  :smiling_face_with_3_hearts:  
 
//vidime sa veľmi skoro, moje slnko
	
const int N = 2e5+5;

int n,m;
int a[N], b[N];
bitset<N> vis;
bitset<N> ok;
vector<int> adj[N];

int can(int u, int x) {
	vis.reset();
	queue<int> q; q.push(u);
	int ans=0;
	while (q.size()) {
		auto u=q.front(); q.pop();
		if (a[u]==x) ans=1;
		if (ok[u]) continue;
		if (vis[u]) continue;
		vis[u]=1;
		for(auto&v:adj[u]) q.push(v);
	}
	return ans;
}

void solve() {

	cin>>n>>m;
	forn(i,n) cin>>a[i];
	forn(i,n) cin>>b[i];
	vector<pi> e(m);
	forn(i,m) cin>>e[i].f>>e[i].s;

	forn(i,n) {
		if (a[i]<b[i]) {
			cout<<"0\n"; return;
		}
	}

	forn(i,n) adj[i].clear();
	ok.reset();
	forn(i,m) {
		int u=e[i].f, v=e[i].s; --u, --v;
		adj[u].pb(v);
		adj[v].pb(u);
	}

	vector<pi> v;
	forn(i,n) v.pb({b[i],i});
	sort(rall(v));

	for(auto&x:v) {
		int z = can(x.s, x.f);
		if (!z) {
			cout<<"0\n"; return;
		}
		ok[x.s]=1;
	}
	cout<<"1\n";

}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t=1;
    cin>>t;
    while (t--) solve();
    return 0;
}

Compilation message

colors.cpp:3:1: warning: multi-line comment [-Wcomment]
    3 | //\
      | ^
colors.cpp:9:1: warning: multi-line comment [-Wcomment]
    9 | //   \ __ __  \
      | ^
colors.cpp:36:1: warning: multi-line comment [-Wcomment]
   36 | // \
      | ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 89 ms 8272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 8536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 56 ms 8272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 56 ms 8272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 89 ms 8272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 158 ms 9808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 7492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 89 ms 8272 KB Output isn't correct
2 Halted 0 ms 0 KB -