Submission #643141

# Submission time Handle Problem Language Result Execution time Memory
643141 2022-09-21T09:30:52 Z SlavicG Colors (RMI18_colors) C++17
47 / 100
3000 ms 42312 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);
    }
    vector<int> nodes[n + 1];
    for(int i = 0; i < n; ++i) nodes[a[i]].pb(i);
    int j = n;
    while(true) {
        int u = -1;
        while(j > 0 && !sz(nodes[j])) --j;
        if(j >= 0 && sz(nodes[j])) {
            u = nodes[j].back();
            nodes[j].pop_back();
        }
        if(u == -1) break;
        for(int v: adj[u]) {
            if(a[v] != b[v] && a[v] > a[u]) {
                a[v] = a[u];
                nodes[a[v]].pb(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 67 ms 2824 KB Output is correct
2 Correct 41 ms 2776 KB Output is correct
3 Correct 18 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 2708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 2676 KB Output is correct
2 Correct 18 ms 2692 KB Output is correct
3 Correct 3 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 2676 KB Output is correct
2 Correct 18 ms 2692 KB Output is correct
3 Correct 3 ms 2772 KB Output is correct
4 Correct 97 ms 2684 KB Output is correct
5 Execution timed out 3076 ms 6720 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 67 ms 2824 KB Output is correct
2 Correct 41 ms 2776 KB Output is correct
3 Correct 18 ms 4180 KB Output is correct
4 Correct 48 ms 2676 KB Output is correct
5 Correct 18 ms 2692 KB Output is correct
6 Correct 3 ms 2772 KB Output is correct
7 Correct 61 ms 2700 KB Output is correct
8 Correct 28 ms 2752 KB Output is correct
9 Correct 16 ms 3332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 170 ms 2736 KB Output is correct
2 Execution timed out 3079 ms 42312 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 2644 KB Output is correct
2 Correct 14 ms 2772 KB Output is correct
3 Correct 23 ms 3000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 2824 KB Output is correct
2 Correct 41 ms 2776 KB Output is correct
3 Correct 18 ms 4180 KB Output is correct
4 Correct 58 ms 2708 KB Output is correct
5 Correct 48 ms 2676 KB Output is correct
6 Correct 18 ms 2692 KB Output is correct
7 Correct 3 ms 2772 KB Output is correct
8 Correct 97 ms 2684 KB Output is correct
9 Execution timed out 3076 ms 6720 KB Time limit exceeded
10 Halted 0 ms 0 KB -