问题类型:排序,数组。
03pie’s solution for [UVA-10763]:
题目链接
#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm> const int maxn=500005;
using namespace std;
int arr[maxn]; void swap(int a,int b){ int t=arr[a]; arr[a] = arr[b]; arr[b] = t;
} void init(){ for(int i=0; i<maxn; ++i) arr[i] = i;
}
bool isOk(){ for(int i=0; i<maxn; ++i) if(arr[i]!=i) return false; return true;
}
int main() {
// freopen("F://inp.txt","r",stdin);int n, i, a, b; while(scanf("%d",&n), n){init(); for(int i=0; i<n; ++i){ scanf("%d %d", &a, &b); swap(a, b); } printf("%s\n",isOk()?"YES":"NO");} return 0;
}