Submission #443245

#TimeUsernameProblemLanguageResultExecution timeMemory
443245valerikkColors (RMI18_colors)C++17
47 / 100
3074 ms7384 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1.5e5 + 123; int n, m; int a[N], b[N]; vector<int> g[N]; bool used[N], f[N]; bool solve() { 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 < n; i++) g[i].clear(); while (m--) { int v, u; cin >> v >> u; v--, u--; g[v].push_back(u); g[u].push_back(v); } for (int i = 0; i < n; i++) { if (a[i] < b[i]) return 0; } for (int i = 0; i < n; i++) f[i] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) used[j] = 0; used[i] = 1; queue<int> q; q.push(i); while (!q.empty()) { int v = q.front(); q.pop(); for (int u : g[v]) { if (!used[u] && a[u] >= a[i] && b[u] <= a[i]) { used[u] = 1; q.push(u); } } } for (int j = 0; j < n; j++) { if (used[j] && b[j] == a[i]) f[j] = 1; } } for (int i = 0; i < n; i++) { if (!f[i]) return 0; } return 1; } int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { cout << (solve() ? "1" : "0") << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...