ACM:POJ 3660 Cow Contest-floyd algorithm

Source: Internet
Author: User
Tags rounds

Link Cow ContestTime limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld &% Llu

Description

n (1≤ n ≤100) cows, conveniently numbered 1.. N, is participating in a programming contest. As we all know, some cows code better than others. Each cow have a certain constant skill rating that is unique among the competitors.

The contest is conducted in several head-to-head rounds and each between. If Cow A has a greater skill level than cow b (1≤ An; 1≤ bn; ab), then cow A would always beat Cow b.

Farmer John was trying to rank the cows by skill. Given A list the results of m (1≤ M ≤4,500) Two-cow rounds, determine the number of cows whose ran KS can is precisely determined from the results. It is guaranteed that the results of the rounds would not be contradictory.

Input

* Line 1:two space-separated integers: N and M
* Lines 2. M+1:each line contains, space-separated integers that describe the competitors and results (the first integer , a, is the winner) of a round of competition: a and B

Output

* Line 1: A single integer representing the number of cows whose ranks can be determined
 

Sample Input

5 54 34 23 21 22 5

Sample Output

2

/* /test Instructions: There are n cows, 22 compared, strong in front, 鶸 in the rear. Ask the M-round comparison to be able to know how many cattle specific rankings. Using the Floyd algorithm to judge the relationship between the N cattle, if a cow and another n-1 cattle have built a relationship, it means that the cow has been tender to exclude the order. AC Code:/*



#include "algorithm" #include "iostream" #include "CString" #include "cstdlib" #include "Cstdio" #include "string" # Include "vector" #include "queue" #include "Cmath" using namespace std;typedef long long LL; #define MEMSET (x, y) memset (x, Y, sizeof (x)) #define MEMCPY (x, y) memcpy (x,y,sizeof) #define FK (x) cout<< "[" <<x<< "]\n" int cow[105][ 105];void Floyd (int n) {for (int k=1, k<=n; k++) {for (Int. I=1; i<=n; i++) {for (int j=1; j<=n; J + +) {cow[i][j]=cow[ i][j]| |  (Cow[i][k]&&cow[k][j]); The relationship between two cows is determined if the relationship between them has been determined, or if both cows and a single cow have a sequential relationship. cout<< "[" <<cow[i][j]<< "]";} Puts ("");} Puts ("");}} int main () {int n,m,w,l,num,ans;while (~scanf ("%d%d", &n,&m)) {memset (cow,0); for (int i=0; i<m; i++) {scanf ("% d%d ", &w,&l); cow[w][l]=1;} Floyd (n); ans=0;for (int i=1; i<=n; i++) {num=0;for (int j=1; j<=n; J + +) {if (cow[i][j]| | Cow[j][i]) num++;//If the relationship between the cow and other cows is determined, count. }if (num==n-1) ans++;//if the cow and all the other cattle relations are determined, the position of the cow has been found. }printf ("%d\n", ans); return 0;}

  

ACM:POJ 3660 Cow Contest-floyd algorithm

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.