Bzoj 1703 [Usaco2007 mar]ranking the Cows cow ranking Bitset optimization

Source: Internet
Author: User
Tags bitset

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.