# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
261714 | 2020-08-12T02:53:19 Z | cheeheng | Colors (RMI18_colors) | C++14 | 179 ms | 4092 KB |
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> ii; vector<int> AdjList[150005]; int a[150005]; int b[150005]; ii ab[150005]; int deg[150005]; int main(){ int t; scanf("%d", &t); while(t --){ int N, M; scanf("%d%d", &N, &M); for(int i = 1; i <= N; i ++){ AdjList[i].clear(); deg[i] = 0; } set<int> s1; for(int i = 1; i <= N; i ++){ scanf("%d", &a[i]); s1.insert(a[i]); } for(int i = 1; i <= N; i ++){ scanf("%d", &b[i]); } for(int i = 0; i < M; i ++){ int u, v; scanf("%d%d", &u, &v); AdjList[u].push_back(v); AdjList[v].push_back(u); deg[u] ++; deg[v] ++; } int ans = 1; for(int i = 1; i <= N; i ++){ if(b[i] > a[i] || s1.find(b[i]) == s1.end()){ ans = 0; break; } } if(ans == 0){ printf("0\n"); continue; } int starVertex = -1; for(int i = 1; i <= N; i ++){ if(deg[i] == N-1){ starVertex = i; break; } } if(starVertex != -1){ for(int i = 1; i <= N; i ++){ if(i == starVertex){continue;} if(b[i] <= a[starVertex] || b[i] == a[i]){ }else{ ans = 0; break; } } printf("%d\n", ans); continue; } if((long long)M == (long long)N*(N-1)/2){ multiset<int> s; for(int i = 1; i <= N; i ++){ ab[i] = ii(a[i], b[i]); s.insert(a[i]); } sort(ab+1, ab+(N+1), greater<ii>()); for(int i = 1; i <= N; i ++){ if(ab[i].first == ab[i].second){continue;} if(ab[i].first < ab[i].second){ ans = 0; break; } if(s.find(ab[i].second) != s.end()){ }else{ ans = 0; break; } s.erase(s.find(ab[i].first)); } printf("%d\n", ans); continue; } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 88 ms | 4092 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 79 ms | 3840 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 95 ms | 3840 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 95 ms | 3840 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 88 ms | 4092 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 179 ms | 3988 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 38 ms | 3872 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 88 ms | 4092 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |