# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
557865 |
2022-05-06T07:41:07 Z |
FatihSolak |
Colors (RMI18_colors) |
C++17 |
|
3000 ms |
22200 KB |
#include <bits/stdc++.h>
#define N 200005
using namespace std;
int a[N];
int b[N];
vector<int> adj[N];
set<int> s[N];
bool ok[N];
bool vis[N];
void dfs(int v,int par){
vis[v] = 1;
s[v] = {a[v]};
for(auto u:adj[v]){
if(u == par)continue;
if(!vis[u])
dfs(u,v);
for(auto c:s[u])
s[v].insert(c);
}
while(*s[v].begin() < b[v])
s[v].erase(*s[v].begin());
while(*s[v].rbegin() > a[v])
s[v].erase(*s[v].rbegin());
if(s[v].count(b[v]))
ok[v] = 1;
}
void solve(){
int n,m;
cin >> n >> m;
for(int i = 1;i<=n;i++){
cin >> a[i];
adj[i].clear();
ok[i] = 0;
}
for(int i = 1;i<=n;i++){
cin >> b[i];
}
for(int i = 1;i<=m;i++){
int u,v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i = 1;i<=n;i++){
if(a[i] < b[i]){
cout << 0 << endl;
return;
}
}
for(int i = 1;i<=n;i++){
for(int j = 1;j<=n;j++)vis[j] = 0;
dfs(i,0);
}
for(int i = 1;i<=n;i++){
if(!ok[i]){
cout << 0 << endl;
return;
}
}
cout << 1 << endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
cin >> t;
while(t--){
solve();
}
#ifdef Local
cout << endl << fixed << setprecision(2) << 1000.0*clock()/CLOCKS_PER_SEC << " milliseconds.";
#endif
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
786 ms |
14444 KB |
Output is correct |
2 |
Correct |
847 ms |
14540 KB |
Output is correct |
3 |
Correct |
960 ms |
14608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3072 ms |
14752 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
883 ms |
14432 KB |
Output is correct |
2 |
Correct |
996 ms |
14452 KB |
Output is correct |
3 |
Correct |
886 ms |
14720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
883 ms |
14432 KB |
Output is correct |
2 |
Correct |
996 ms |
14452 KB |
Output is correct |
3 |
Correct |
886 ms |
14720 KB |
Output is correct |
4 |
Correct |
2998 ms |
14444 KB |
Output is correct |
5 |
Execution timed out |
3057 ms |
22200 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
786 ms |
14444 KB |
Output is correct |
2 |
Correct |
847 ms |
14540 KB |
Output is correct |
3 |
Correct |
960 ms |
14608 KB |
Output is correct |
4 |
Correct |
883 ms |
14432 KB |
Output is correct |
5 |
Correct |
996 ms |
14452 KB |
Output is correct |
6 |
Correct |
886 ms |
14720 KB |
Output is correct |
7 |
Correct |
999 ms |
14552 KB |
Output is correct |
8 |
Correct |
1008 ms |
14584 KB |
Output is correct |
9 |
Correct |
1958 ms |
14676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3095 ms |
14464 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3072 ms |
14816 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
786 ms |
14444 KB |
Output is correct |
2 |
Correct |
847 ms |
14540 KB |
Output is correct |
3 |
Correct |
960 ms |
14608 KB |
Output is correct |
4 |
Execution timed out |
3072 ms |
14752 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |