Codeforces Round #382 (Div. 1), problem: (D) Permutations Solution in C/C++

#include <bits/stdc++.h>
using namespace std; 

const int N=2e3+1;

int n,m,x[N*N],y[N*N];
bitset<N*2> a[N];

int main() {
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++) {
		scanf("%d%d",x+i,y+i);
		x[i]--; y[i]--;
		a[x[i]].set(y[i]);
	} 
	for(int i=0;i<n;i++) a[i][i+n]=1;
	for(int i=0;i<n;i++) {
		for(int j=i;j<n;j++) {
			if(a[j][i]) {
				swap(a[j],a[i]);
				break;
			}
		}
		for(int j=0;j<n;j++) {
			if(j!=i&&a[j][i]) a[j]^=a[i];
		}
	}
	for(int i=1;i<=m;i++) {
		if(a[y[i]][n+x[i]]) puts("NO");
		else puts("YES");		
	}
}
(Visited 31 times, 1 visits today)

About the Author:

Leave A Comment