[TOJ 3955] nku acm football match (weighted sum query set), tojnku

Source: Internet
Author: User

[TOJ 3955] nku acm football match (weighted sum query set), tojnku

Description

Nku acm is about to hold a football match recently. As the event owner, Lee wants to team up registrants. The team should follow the following principles:

One person cannot join multiple teams;
People you don't know can't be in the same team;
If a and B know each other and B and c know each other, a and c also know each other;
Each team has a maximum of 8 members and a minimum of 5 members;
Try to make the team full.
Due to the large number of participants, Lee says there is nothing to do, so please help Lee program how many teams there are in the competition.

Input

Enter two integers in the first line. n and m, n (1 <= n <= 300000) represent the number of registrants, and m (1 <= m <= 500000) represent the number of links. In the next m row, two integers a (1 <= a <= n) and B (1 <= B <= n) indicate that a and B recognize each other.

Output

The output line contains an integer indicating the number of teams.

Sample Input

11 10
1 2
2 3
2 6
3 4
4 5
5 6
7 9
9 11
11 8
8 10

Sample output

2

# Include <iostream> # include <algorithm> using namespace std; int p [300005], rank [300005]; int find (int r) {if (p [r]! = R) p [r] = find (p [r]); return p [r];} int join (int x, int y) {int fx = find (x), fy = find (y); if (fx! = Fy) {p [fx] = fy; rank [fy] + = rank [fx]; rank [fx] = 1; // change the added rank array to 1} int main () {int n, m, a, B, s; while (cin> n> m) {s = 0; for (int I = 0; I <= 300005; I ++) p [I] = I, rank [I] = 1; while (m --) {scanf ("% d", & a, & B); join (a, B) ;}for (int I = 1; I <= n; I ++) {if (rank [I]> = 5) {if (rank [I] % 8> = 5) s + = rank [I]/8 + 1; else s + = rank [I]/8;} printf ("% d \ n", s);} return 0 ;}

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.