Submission #899806

# Submission time Handle Problem Language Result Execution time Memory
899806 2024-01-07T03:43:31 Z Cookie Colors (RMI18_colors) C++14
0 / 100
156 ms 27720 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359;
using u128 = __uint128_t;
const int x[4] = {1, 0, -1, 0};
const int y[4] = {0, -1, 0, 1};
const ll mod = 1e9 + 7;
const int mxn = 3e5 + 69, mxq = 1e5 + 5, sq = 500, mxv = 2e7 + 5;
//const int base = (1 <<18);
const int inf = 1e9 + 5, neg = -69420;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//const int x[9] = {0, 1, 1, -1, -1, 2, -2, 2, -2};
//const inty[9] = {0, 2, -2, 2, -2, 1, 1, -1, -1};
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int n, m;
vt<int>adj[mxn + 1];
bool vis[mxn + 1];
vt<int>compa[mxn + 1], compb[mxn + 1];
int seen[mxn + 1], a[mxn + 1], b[mxn + 1];
void solve(){
    //for(int i = 1; i <= n; i++)pa[i] = -1;
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        seen[i] = 0; compa[i].clear();  compb[i].clear(); adj[i].clear();
    }
    for(int i = 1; i <= n; i++){
        cin >> a[i]; seen[a[i]] = 1; compa[a[i]].pb(i);
    }
    for(int i = 1; i <= n; i++){
        cin >> b[i]; compb[b[i]].pb(i);
    }
    for(int i = 1; i <= n; i++){
        if(b[i] > a[i] || !seen[b[i]]){
            cout << 0 << "\n";
            return;
        }
    }
    for(int i = 0; i < m; i++){
        int u, v; cin >> u >> v;
        adj[u].pb(v); adj[v].pb(u);
    }
    for(int i = n; i >= 1; i--){
        queue<int>q;
        for(int j = 1; j <= n; j++)vis[j] = 0;
        for(auto j: compa[i]){
            vis[j] = 0; q.push(j);
        }
        while(!q.empty()){
            int nw = q.front(); q.pop();
            for(auto j: adj[nw]){
                if(b[j] > i)continue;
                if(!vis[j]){
                    vis[j] = 1; q.push(j);
                }
            }
        }
        for(auto j: compb[i]){
            if(!vis[j]){
                cout << 0 << "\n";
                return;
            }
        }
    }
    cout << 1 << "\n";
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("COLLEGE.INP", "r", stdin);
    //freopen("COLLEGE.OUT", "w", stdout);
    int tt; cin >> tt;
    while(tt--){
        solve();
    }

    return(0);
}
/*
6 2
1 2
1 3
1 4
1 5
1 6
2 2
5 6
*/
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 25436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 25180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 25508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 25508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 25436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 156 ms 27720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 25180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 25436 KB Output isn't correct
2 Halted 0 ms 0 KB -