[BZOJ1006] [HNOI2008] The Magical Kingdom (chord chart)

Source: Internet
Author: User

Description

The Kingdom of K is a country of keen triangle, even people's intercourse also only like the triangle principle. They think triangular relationship: that AB mutual understanding, BC Mutual Understanding, CA
Mutual understanding, is concise and efficient. In order to consolidate triangular relations, the K-State prohibits the existence of four-sided relations, five-sided relations and so on. The so-called N-side relationship, refers to n personal a1a2
... There is only n pairs of cognitive relationships between an: (A1A2) (A2A3) ... (AnA1), without other cognitive relationships. For example, four-sided relationship refers to ABCD four persons ab,bc,c
D,da know each other, and ac,bd do not know each other. In order to prevent the disadvantage of the race, it is stipulated that any pair of mutual acquaintance shall not be in a team, the King knows,
At least how many teams can be divided.

Input

The first row of two integers n,m. 1<=n<=10000,1<=m<=1000000. Indicates that there are N individuals, M to the cognitive relationship. Next, enter a pair of friends on each line of M line
Friends

Output

Output an integer, at least how many teams can be divided

Sample Input4 5
1 2
1 4
2 4
2 3
3 4Sample Output3HINT

One scenario (1,3) (2) (4)

SourceSolution

CDQ "Chord and Interval map" thesis title

Test instructions guarantee diagram is a string diagram, and then the topic is to find the minimum dyeing, so with the $mcs$ algorithm to find a perfect elimination sequence, backward greedy can, the paper has explained

The original paper used a bucket order to make it for $o (n+m) $, Konjac Konjac IQ balance is not enough to read, so use the priority queue, probably $o ((n+m) log (n+m)) $

(Gee, a lot of people are $o (n^2+m) $?) Ah, not afraid of fear! )

1#include <bits/stdc++.h>2 using namespacestd;3 structEdge4 {5     intV, NXT;6}e[2000005];7 intfst[10005], label[10005], s[10005], vis[10005];8priority_queue<pair<int,int> >PQ;9  Ten voidAddedge (intIintUintv) One { AE[i] = (edge) {V, Fst[u]}, fst[u] =i; - } -   the intMain () - { -     intN, M, u, V, ans =0; -scanf"%d%d", &n, &m); +      for(inti =1; I <= m; ++i) -     { +scanf"%d%d", &u, &v); AAddedge (i <<1, u, v); atAddedge (i <<1|1, V, u); -     } -      for(inti =1; I <= N; ++i) -Pq.push (Make_pair (0, i)); -      for(inti = n; I --i) -     { inU =Pq.top (). Second, Pq.pop (); -          while(Vis[u]) toU =Pq.top (). Second, Pq.pop (); +S[i] = u, vis[u] =-1; -          for(intj = Fst[u]; J j =e[j].nxt) the         { *v =e[j].v; $             if(Vis[v])Continue;Panax NotoginsengPq.push (Make_pair (+ +Label[v], v)); -         } the     } +memset (Label,0,sizeof(label)); A      for(inti = n; I --i) the     { +          for(intj = Fst[s[i]]; J j =e[j].nxt) -VIS[LABEL[E[J].V]] =i; $          for(intj =1; ; ++j) $             if(Vis[j]! =i) -             { -Label[s[i]] = j, ans =Max (ans, j); the                  Break; -             }Wuyi     } theprintf"%d\n", ans); -     return 0; Wu}
View Code

[BZOJ1006] [HNOI2008] The Magical Kingdom (chord chart)

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.