Submission #1106302

# Submission time Handle Problem Language Result Execution time Memory
1106302 2024-10-29T19:27:46 Z lovrot Colors (RMI18_colors) C++17
0 / 100
106 ms 33352 KB
#include <cstdio>
#include <vector>
#include <set>
#include <cstring>
#include <algorithm>

using namespace std; 

typedef long long ll;
typedef pair<int, int> pii;

const int N = 3e5 + 10;

int n, m, a[N], b[N];
vector<int> g[N], col[N];

int un[N];
set<int> in[N];

int trazi(int u) { 
	return un[u] == u ? u : un[u] = trazi(un[u]); 
}

void unija(int u, int v) { 
	u = trazi(u);
	v = trazi(v);
	if(u == v) { return; }
	if(in[u].size() < in[v].size()) { swap(u, v); }
	
	for(int x : in[v]) { in[u].insert(x); }
	un[v] = u;
}

void solve() { 
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) { 
		scanf("%d", a + i);
		col[i].clear();
	}
	for(int i = 1; i <= n; ++i) { 
		scanf("%d", b + i);
		un[i] = i;
		g[i].clear(); 
		in[i].clear(); 
		in[i].insert(a[i]);
		col[b[i]].push_back(i);
	}

	for(; m--; ) {
		int u, v; scanf("%d%d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}

	for(int i = 1; i <= n; ++i) { 
		for(int u : col[i]) { 
			for(int v : g[u]) { 
				if(b[v] <= b[u]) {
					unija(u, v);
				}
			}
		}

		for(int u : col[i]) {
			if(in[trazi(u)].find(b[u]) == in[trazi(u)].end()) {
				printf("0\n");
				return;
			}
		}
	}
	printf("1\n");
	return;
}

int main() { 
	int t;
	scanf("%d", &t);
	for(; t--; ) solve();
	return 0;
}

Compilation message

colors.cpp: In function 'void solve()':
colors.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
colors.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |   scanf("%d", a + i);
      |   ~~~~~^~~~~~~~~~~~~
colors.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |   scanf("%d", b + i);
      |   ~~~~~^~~~~~~~~~~~~
colors.cpp:50:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |   int u, v; scanf("%d%d", &u, &v);
      |             ~~~~~^~~~~~~~~~~~~~~~
colors.cpp: In function 'int main()':
colors.cpp:77:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |  scanf("%d", &t);
      |  ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 31560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 31816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 60 ms 31560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 60 ms 31560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 31560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 106 ms 33352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 30952 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 31560 KB Output isn't correct
2 Halted 0 ms 0 KB -