Submission #873437

# Submission time Handle Problem Language Result Execution time Memory
873437 2023-11-15T05:39:32 Z vjudge1 Colors (RMI18_colors) C++17
47 / 100
3000 ms 12372 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 = 2e5 + 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;
int us[maxn];
vector<int>g[maxn];

int dfs(int v, int x){
    us[v] = sz;
    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) continue;
        ans |= dfs(to, x);
    } 
    return 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();
    }
    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 Correct 48 ms 6992 KB Output is correct
2 Correct 25 ms 6748 KB Output is correct
3 Correct 11 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 6744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 6748 KB Output is correct
2 Correct 15 ms 7260 KB Output is correct
3 Correct 3 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 6748 KB Output is correct
2 Correct 15 ms 7260 KB Output is correct
3 Correct 3 ms 6748 KB Output is correct
4 Correct 74 ms 9852 KB Output is correct
5 Execution timed out 3043 ms 12372 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 6992 KB Output is correct
2 Correct 25 ms 6748 KB Output is correct
3 Correct 11 ms 6748 KB Output is correct
4 Correct 35 ms 6748 KB Output is correct
5 Correct 15 ms 7260 KB Output is correct
6 Correct 3 ms 6748 KB Output is correct
7 Correct 45 ms 8080 KB Output is correct
8 Correct 24 ms 7260 KB Output is correct
9 Correct 23 ms 6912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 6836 KB Output is correct
2 Execution timed out 3057 ms 8752 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 6748 KB Output is correct
2 Correct 15 ms 7160 KB Output is correct
3 Correct 30 ms 6744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 6992 KB Output is correct
2 Correct 25 ms 6748 KB Output is correct
3 Correct 11 ms 6748 KB Output is correct
4 Correct 56 ms 6744 KB Output is correct
5 Correct 35 ms 6748 KB Output is correct
6 Correct 15 ms 7260 KB Output is correct
7 Correct 3 ms 6748 KB Output is correct
8 Correct 74 ms 9852 KB Output is correct
9 Execution timed out 3043 ms 12372 KB Time limit exceeded
10 Halted 0 ms 0 KB -