Test Instructions:Link
Method:Bitset Delivery Closure
parsing:Obviously the answer is the number of unordered point pairs. But what about the number of disordered points? The principle of tolerance and repulsion. The answer is the number of all point pairs minus ordered point pairs. How to maintain the number of ordered points? Bitset transitive closures. The first time in life Rnk1!!!!!!!!!!!
Code:
#include <bitset>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 1010using namespace STD;intN,m,cnt,cnt2;intHead[n];intV[n]; bitset<N>B[n];structnode{intFrom,to,next;} edge[n*Ten];voidInit () {memset(head,-1,sizeof(head)); Cnt=1;}voidEdgeadd (intFromintTo) {Edge[cnt].from=from; Edge[cnt].to=to; Edge[cnt].next=head[from]; head[from]=cnt++;}intRetvoidDfsintx) {v[x]=1; for(inti=head[x];i!=-1; i=edge[i].next) {intto=edge[i].to;if(!v[to]) DFS (to); B[x]|=b[to]; }}intAnsintMain () {scanf("%d%d", &n,&m); Init (); for(intI=1; i<=n;i++) b[i][i]=1; for(intI=1; i<=m;i++) {intx, y;scanf("%d%d", &x,&y); Edgeadd (x, y); } for(intI=1; i<=n;i++) {if(!v[i]) DFS (i); } for(intI=1; i<=n;i++) {ans+=b[i].count (); }printf("%d\n", N (n1)/2-ans+n);}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Bzoj 1703 [Usaco2007 mar]ranking the Cows cow ranking Bitset optimization