#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(I, L, R) for(int I(L) ; I <= (int)R ; ++I)
#define FOD(I, R, L) for(int I(R) ; I >= (int)L ; --I)
#define FOA(I, A) for(auto &I : A)
#define print(A,L,R) FOR(OK, L, R){if(A[OK]<=-oo / 10||A[OK]>=oo)cout<<"- ";else cout<<A[OK]<<' ';}cout<<'\n';
#define prints(A) FOA(OK, A){cout<<OK<<' ';}cout << '\n';
#define printz(A,L,R) FOR(OK, 0, L){FOR(KO, 0, R){if(A[OK][KO]>-oo&&A[OK][KO]<oo)cout<<A[OK][KO]<<' ';else cout << "- ";} cout << '\n';}cout << '\n';
#define fs first
#define sd second
#define ii pair<int,int>
#define iii pair<int, ii>
#define all(A) A.begin(), A.end()
#define quickly ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILE "LEASTSUMQ"
const int N = 3e5 + 5;
const int mod = 1e9 + 7;
const int oo = 1e18;
struct Modint{
int x;
Modint(){x = 0;}
Modint(int _x){ x = (_x % mod + mod) % mod; }
inline Modint operator + (const Modint &other) const{ return (x + other.x) % mod; }
inline Modint operator - (const Modint &other) const{ return (x - other.x + mod) % mod; }
inline Modint operator * (const Modint &other) const{ return (1LL * x * other.x) % mod; }
inline void operator += (const Modint &other){ *this = *this + other; }
inline void operator -= (const Modint &other){ *this = *this - other; }
inline void operator *= (const Modint &other){ *this = *this * other; }
friend ostream& operator << (ostream& os, const Modint &t){ return os << t.x; }
};
int n, m;
int a[N], b[N];
bool check[N], run[N];
vector<int> g[N], to[N], rev[N];
struct DSU{
int parent[N];
void build(){
FOR(i, 1, n) parent[i] = 0;
}
int found(int u){
return (parent[u] == 0 ? u : (parent[u] = found(parent[u])));
}
void setting(int u, int v){
int U = found(u);
int V = found(v);
if(U != V) parent[V] = U;
}
} dsu;
void reset(){
FOR(i, 1, n){
g[i].clear();
to[i].clear();
rev[i].clear();
}
}
bool solve(){
cin >> n >> m;
FOR(i, 1, n){
cin >> a[i];
}
FOR(i, 1, n){
cin >> b[i];
}
FOR(i, 1, n){
if(b[i] > a[i]){
return 0;
}
}
FOR(i, 1, n){
to[b[i]].push_back(i);
rev[a[i]].push_back(i);
}
FOR(i, 1, m){
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
FOD(i, 3, 1){
dsu.build();
FOR(u, 1, n) check[u] = run[u] = 0;
FOR(u, 1, n){
if(b[u] <= i && i <= a[u]){
run[u] = 1;
}
}
FOR(u, 1, n){
if(!run[u]) continue;
FOA(v, g[u]){
if(run[v]){
dsu.setting(u, v);
}
}
}
FOA(u, rev[i]){
check[dsu.found(u)] = 1;
}
FOA(v, to[i]){
if(check[dsu.found(v)] == 0){
return 0;
}
}
}
reset();
return 1;
}
signed main(){ quickly
if(fopen(FILE".inp", "r")){
freopen(FILE".inp", "r", stdin);
freopen(FILE".out", "w", stdout);
}
int test; cin >> test;
while(test--){
cout << solve() << '\n';
}
}
컴파일 시 표준 에러 (stderr) 메시지
colors.cpp: In function 'int main()':
colors.cpp:142:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
142 | freopen(FILE".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
colors.cpp:143:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
143 | freopen(FILE".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |