Submission #643133

# Submission time Handle Problem Language Result Execution time Memory
643133 2022-09-21T09:16:59 Z SlavicG Colors (RMI18_colors) C++17
47 / 100
3000 ms 8292 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;
    forn(i, n) adj[i].clear();
    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) {
        nodes.push({a[i], i});
    }

    while(!nodes.empty()) {
        int u = nodes.top().second;
        nodes.pop();
        for(int v: adj[u]) {
            if(a[v] != b[v] && a[v] > a[u]) {
                a[v] = a[u];
                nodes.push({a[v], v});
            }
        }
    }
    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 Correct 122 ms 2696 KB Output is correct
2 Correct 116 ms 3176 KB Output is correct
3 Correct 107 ms 2832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 2692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 2668 KB Output is correct
2 Correct 29 ms 3184 KB Output is correct
3 Correct 4 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 2668 KB Output is correct
2 Correct 29 ms 3184 KB Output is correct
3 Correct 4 ms 2772 KB Output is correct
4 Correct 121 ms 5724 KB Output is correct
5 Execution timed out 3077 ms 8292 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 122 ms 2696 KB Output is correct
2 Correct 116 ms 3176 KB Output is correct
3 Correct 107 ms 2832 KB Output is correct
4 Correct 67 ms 2668 KB Output is correct
5 Correct 29 ms 3184 KB Output is correct
6 Correct 4 ms 2772 KB Output is correct
7 Correct 92 ms 4084 KB Output is correct
8 Correct 61 ms 3248 KB Output is correct
9 Correct 71 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 250 ms 2840 KB Output is correct
2 Execution timed out 3070 ms 4964 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 2644 KB Output is correct
2 Correct 21 ms 3028 KB Output is correct
3 Correct 67 ms 2832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 2696 KB Output is correct
2 Correct 116 ms 3176 KB Output is correct
3 Correct 107 ms 2832 KB Output is correct
4 Correct 67 ms 2692 KB Output is correct
5 Correct 67 ms 2668 KB Output is correct
6 Correct 29 ms 3184 KB Output is correct
7 Correct 4 ms 2772 KB Output is correct
8 Correct 121 ms 5724 KB Output is correct
9 Execution timed out 3077 ms 8292 KB Time limit exceeded
10 Halted 0 ms 0 KB -