Submission #899810

# Submission time Handle Problem Language Result Execution time Memory
899810 2024-01-07T03:56:13 Z Cookie Colors (RMI18_colors) C++14
47 / 100
3000 ms 32332 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 = 0; i < m; i++){
        int u, v; cin >> u >> v;
        adj[u].pb(v); adj[v].pb(u);
    }
  for(int i = 1; i <= n; i++){
        if(b[i] > a[i] || !seen[b[i]]){
            cout << 0 << "\n";
            return;
        }
    }
    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] = 1; q.push(j);
        }
        while(!q.empty()){
            int nw = q.front(); q.pop();
            for(auto j: adj[nw]){
                if(b[j] > i || a[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);
}
# Verdict Execution time Memory Grader output
1 Correct 48 ms 25176 KB Output is correct
2 Correct 25 ms 25688 KB Output is correct
3 Correct 11 ms 25436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 25244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 25232 KB Output is correct
2 Correct 18 ms 25692 KB Output is correct
3 Correct 7 ms 25256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 25232 KB Output is correct
2 Correct 18 ms 25692 KB Output is correct
3 Correct 7 ms 25256 KB Output is correct
4 Correct 79 ms 28244 KB Output is correct
5 Execution timed out 3042 ms 32332 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 25176 KB Output is correct
2 Correct 25 ms 25688 KB Output is correct
3 Correct 11 ms 25436 KB Output is correct
4 Correct 46 ms 25232 KB Output is correct
5 Correct 18 ms 25692 KB Output is correct
6 Correct 7 ms 25256 KB Output is correct
7 Correct 50 ms 26656 KB Output is correct
8 Correct 23 ms 25688 KB Output is correct
9 Correct 10 ms 25180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 25192 KB Output is correct
2 Execution timed out 3048 ms 30708 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 25176 KB Output is correct
2 Correct 22 ms 25564 KB Output is correct
3 Correct 21 ms 25432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 25176 KB Output is correct
2 Correct 25 ms 25688 KB Output is correct
3 Correct 11 ms 25436 KB Output is correct
4 Correct 63 ms 25244 KB Output is correct
5 Correct 46 ms 25232 KB Output is correct
6 Correct 18 ms 25692 KB Output is correct
7 Correct 7 ms 25256 KB Output is correct
8 Correct 79 ms 28244 KB Output is correct
9 Execution timed out 3042 ms 32332 KB Time limit exceeded
10 Halted 0 ms 0 KB -