# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
261748 | 2020-08-12T04:05:06 Z | tqbfjotld | Colors (RMI18_colors) | C++14 | 97 ms | 8824 KB |
#include <bits/stdc++.h> using namespace std; int init[150005]; int fin[150005]; vector<int> adjl[150005]; vector<pair<int,int> > order; queue<pair<int,int> > q; bool visited[150005]; int counter = 0; int n,m; bool dfs(int node, int findcol, int finx){ if (init[node]==findcol) return true; visited[node] = true; counter++; //assert(counter<=5000000); for (auto x : adjl[node]){ if (init[x]<finx || fin[x]>finx) continue; if (!visited[x]){ if (dfs(x,findcol,finx)) { init[node] = finx; return true; } } } return false; } void dfs2(int node){ counter++; assert(counter<=n); for (auto x : adjl[node]){ if (init[x]<=init[node] || fin[x]>init[node]){ continue; } init[x] = init[node]; dfs2(x); } } int counter2 = 0; int main(){ int test; scanf("%d",&test); while (test--){ scanf("%d%d",&n,&m); counter2 += n*n; assert(counter2<=5000000); for (int x = 1; x<=n; x++){ scanf("%d",&init[x]); adjl[x].clear(); } bool poss1 = true; order.clear(); for (int x = 1; x<=n; x++){ scanf("%d",&fin[x]); if (fin[x]>init[x]) poss1 = false; order.push_back({init[x],x}); } sort(order.begin(),order.end(),greater<pair<int,int> >()); for (int x = 0; x<m; x++){ int a,b; scanf("%d%d",&a,&b); adjl[a].push_back(b); adjl[b].push_back(a); } if (!poss1) { printf("0\n"); continue; } bool poss = true; /*for (auto x : order){ for (int x = 1; x<=n; x++) visited[x] = false; if (!dfs(x.second,fin[x.second],fin[x.second])){ printf("0\n"); poss = false; break; } }*/ for (auto x : order){ counter = 0; dfs2(x.second); } for (int x = 1; x<=n; x++){ if (init[x]!=fin[x]){ poss = false; printf("0\n"); break; } } if (poss){ printf("1\n"); } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 93 ms | 4604 KB | Output is correct |
2 | Correct | 42 ms | 4472 KB | Output is correct |
3 | Correct | 16 ms | 3968 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 97 ms | 3840 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 84 ms | 4728 KB | Output is correct |
2 | Correct | 33 ms | 4472 KB | Output is correct |
3 | Correct | 6 ms | 3968 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 84 ms | 4728 KB | Output is correct |
2 | Correct | 33 ms | 4472 KB | Output is correct |
3 | Correct | 6 ms | 3968 KB | Output is correct |
4 | Runtime error | 69 ms | 8824 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 93 ms | 4604 KB | Output is correct |
2 | Correct | 42 ms | 4472 KB | Output is correct |
3 | Correct | 16 ms | 3968 KB | Output is correct |
4 | Correct | 84 ms | 4728 KB | Output is correct |
5 | Correct | 33 ms | 4472 KB | Output is correct |
6 | Correct | 6 ms | 3968 KB | Output is correct |
7 | Correct | 91 ms | 5368 KB | Output is correct |
8 | Correct | 39 ms | 4472 KB | Output is correct |
9 | Correct | 16 ms | 3968 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 66 ms | 7800 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 46 ms | 3840 KB | Output is correct |
2 | Correct | 22 ms | 4224 KB | Output is correct |
3 | Correct | 27 ms | 3968 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 93 ms | 4604 KB | Output is correct |
2 | Correct | 42 ms | 4472 KB | Output is correct |
3 | Correct | 16 ms | 3968 KB | Output is correct |
4 | Correct | 97 ms | 3840 KB | Output is correct |
5 | Correct | 84 ms | 4728 KB | Output is correct |
6 | Correct | 33 ms | 4472 KB | Output is correct |
7 | Correct | 6 ms | 3968 KB | Output is correct |
8 | Runtime error | 69 ms | 8824 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
9 | Halted | 0 ms | 0 KB | - |