Submission #863673

# Submission time Handle Problem Language Result Execution time Memory
863673 2023-10-20T17:11:46 Z Andrey Colors (RMI18_colors) C++14
47 / 100
3000 ms 10436 KB
#include<bits/stdc++.h>
using namespace std;

vector<int> col(200001);
vector<int> wow(200001);
vector<int> haha[200001];
vector<bool> bruh(200001);

bool dfs(int a, int c) {
    bruh[a] = false;
    if(col[a] == c) {
        return true;
    }
    for(int i = 0; i < haha[a].size(); i++) {
        if(bruh[haha[a][i]] && wow[haha[a][i]] <= c && col[haha[a][i]] >= c) {
            if(dfs(haha[a][i],c)) {
                return true;
            }
        }
    }
    return false;
}

void solve() {
    int n,m,a,b;
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        haha[i].clear();
    }
    vector<pair<int,int>> wut(0);
    for(int i = 1; i <= n; i++) {
        cin >> col[i];
        wut.push_back({col[i],i});
    }
    sort(wut.begin(),wut.end());
    for(int i = 1; i <= n; i++) {
        cin >> wow[i];
    }
    for(int i = 0; i < m; i++) {
        cin >> a >> b;
        haha[a].push_back(b);
        haha[b].push_back(a);
    }
    for(int i = 0; i < n; i++) {
        a = wut[i].second;
        if(col[a] < wow[a]) {
            cout << 0 << "\n";
            return;
        }
        for(int j = 1; j <= n; j++) {
            bruh[j] = true;
        }
        if(!dfs(a,wow[a])) {
            cout << 0 << "\n";
            return;
        }
    }
    cout << 1 << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Compilation message

colors.cpp: In function 'bool dfs(int, int)':
colors.cpp:14:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for(int i = 0; i < haha[a].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 48 ms 8020 KB Output is correct
2 Correct 26 ms 7256 KB Output is correct
3 Correct 9 ms 7000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 8424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 8012 KB Output is correct
2 Correct 21 ms 7256 KB Output is correct
3 Correct 8 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 8012 KB Output is correct
2 Correct 21 ms 7256 KB Output is correct
3 Correct 8 ms 6748 KB Output is correct
4 Correct 98 ms 9688 KB Output is correct
5 Execution timed out 3016 ms 10436 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 48 ms 8020 KB Output is correct
2 Correct 26 ms 7256 KB Output is correct
3 Correct 9 ms 7000 KB Output is correct
4 Correct 45 ms 8012 KB Output is correct
5 Correct 21 ms 7256 KB Output is correct
6 Correct 8 ms 6748 KB Output is correct
7 Correct 50 ms 8024 KB Output is correct
8 Correct 26 ms 7260 KB Output is correct
9 Correct 23 ms 6744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 9848 KB Output is correct
2 Execution timed out 3051 ms 8672 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 7512 KB Output is correct
2 Correct 8 ms 7004 KB Output is correct
3 Correct 13 ms 6928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 8020 KB Output is correct
2 Correct 26 ms 7256 KB Output is correct
3 Correct 9 ms 7000 KB Output is correct
4 Correct 33 ms 8424 KB Output is correct
5 Correct 45 ms 8012 KB Output is correct
6 Correct 21 ms 7256 KB Output is correct
7 Correct 8 ms 6748 KB Output is correct
8 Correct 98 ms 9688 KB Output is correct
9 Execution timed out 3016 ms 10436 KB Time limit exceeded
10 Halted 0 ms 0 KB -