Submission #873434

# Submission time Handle Problem Language Result Execution time Memory
873434 2023-11-15T05:36:39 Z vjudge1 Colors (RMI18_colors) C++17
0 / 100
56 ms 2652 KB
// #pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")  
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define sz(x) (int)x.size()
#define bit(a, i) ((a>>i)&1)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int P = 31;
const int K = 400;
const ll inf = 1e9;
const ll INF = 1e18;
const int mod = 1e9+7;
const int maxn = 3e3 + 10;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {1, -1, 0, 0};

int a[maxn];
int b[maxn];
int n, m, sz=1;
int us[maxn];
int dp[maxn][maxn];
vector<int>g[maxn];

int dfs(int v, int x){
    us[v] = sz;
    if(dp[v][x] != -1) return dp[v][x];
    if(a[v] < x) return 0;
    if(b[v] > x) return 0;
    if(a[v] == x) return 1;
    int ans = 0;
    for(int to: g[v]){
        if(us[to] < sz)
            ans |= dfs(to, x);
    }
    return dp[v][x] = ans;
}

void ihtw(){
    cin >> n >> m;
    for(int i=1; i<=n; i++) cin >> a[i];
    for(int i=1; i<=n; i++) {
        cin >> b[i];
        g[i].clear();
        fill(dp[i], dp[i]+n+1, -1);
    }
    for(int i=0; i<m; i++){
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    } 
    for(int i=1; i<=n; i++, sz++){
        if(!dfs(i, b[i])){
            cout << "0\n";
            return;
        }
    } cout << "1\n";
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t; cin >> t;
    while(t--) ihtw();
}   
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -