Submission #643126

# Submission time Handle Problem Language Result Execution time Memory
643126 2022-09-21T09:08:52 Z SlavicG Colors (RMI18_colors) C++17
0 / 100
3000 ms 6780 KB
#include "bits/stdc++.h"
using namespace std;

#define ll long long
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define forn(i, n) for(int i = 0; i < n; ++i)

const int N = 1e5 + 10;
vector<int> adj[N];
int a[N], b[N];
void solve() {

    int n, m; cin >> n >> m;
    for(int i = 0; i < n; ++i) cin >> a[i];
    for(int i = 0; i < n; ++i) cin >> b[i];
    for(int i = 0; i < m; ++i) {
        int u, v; cin >> u >> v; --u, --v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    priority_queue<pair<int, int>> nodes;
    for(int i = 0; i < n; ++i) {
        if(a[i] != b[i]) nodes.push({a[i], i});
    }

    while(!nodes.empty()) {
        int u = nodes.top().second;
        nodes.pop();
        int mxsmaller = -1;
        for(int v: adj[u]) {
            if(a[v] < a[u]) mxsmaller = max(mxsmaller, a[v]);
        }
        if(mxsmaller == -1) {
            cout << "0\n";
            return;
        }
        a[u] = mxsmaller;
        if(a[u] != b[u]) nodes.push({a[u], u});
    }
    forn(i, n) {
        if(a[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--) {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Execution timed out 3057 ms 4348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3041 ms 6780 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3031 ms 4224 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3031 ms 4224 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3057 ms 4348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3069 ms 4384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1554 ms 4748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3057 ms 4348 KB Time limit exceeded
2 Halted 0 ms 0 KB -