1006: [hnoi2008] Time Limit: 20 sec memory limit: 162 MB
Submit: 2000 solved: 897
[Submit] [Status] Description
K is a country keen on triangles, and even people only like the triangle principles. they believe that the triangular relationship: AB, BC, and Ca are concise and efficient. in order to consolidate the triangular relationship, K countries prohibit the existence of four-edge relations, five-edge relations, and so on. the so-called n-edge relationship refers to N people a1a2... there are only N pairs of cognitive relationships between an: (a1a2) (a2a3 )... (ana1. for example, four members of ABCD know each other, namely AB, BC, CD, and DA, but AC and BD do not. during the national competition, in order to prevent disadvantages, it was stipulated that any one of the people who knew each other should not be in the same team. The king knew at least how many teams could be divided.
Input
The first line has two integers, N and M. 1 <= n <= random, 1 <= m <= 1000000. It indicates there are n people, M is a relationship with each other, and then input a friend in each line in M.
Output
The output is an integer. The minimum number of teams can be divided.
Sample input4 5
1 2
1 4
2 4
2 3
3 4 sample output3hint
One solution (1, 3) (2) (4)
Returns the smallest color of the string graph.
First, we will introduce some concepts:
1. String
Connect the edges of two non-adjacent points
2. String chart
An undirected graph is called a string graph. If any ring with a length greater than 3 in the graph, there must be at least one string.
3. induced subgraph
This graph is composed of vertices from an undirected graph and vertices at both ends of the edges that belong to the extracted vertices.
That is
4. Simple points
If the induced subgraph of {v} + N (v) is a group, then V is a simple vertex.
5. Perfect elimination sequence
A {v [I]} sequence satisfies any I, so that V [I] is a simple vertex in the induced subgraph of {v [I. N ]}.
For this question, use the MCS method to find the perfect elimination sequence, and then use greedy staining.
MCS algorithm:
1. The order from N to 1 is sequentially given to the vertex number (I is in the perfect elimination sequence)
2. set Label [I] to indicate the number of neighboring vertices of the I-th vertex and the number of known vertices. Select the maximum vertices of label [I] each time and use a linked list to record this step.
For details, see the string chart and interval chart.
#include <iostream>#include <algorithm>#include <cstring>#include <cstdio>#include <cstdlib>using namespace std;struct edge{int y,ne;}e[2000050],e2[2000050];int label[10005];int tot2=0,seq[10005],tot=0,n,m,best=0,v[10005],mark[10005],h2[10005],h[10005],c[10005],ans;void Addedge(int x,int y){tot++;e[tot].y=y;e[tot].ne=h[x];h[x]=tot;}void Add(int x,int y){tot2++;e2[tot2].y=y;e2[tot2].ne=h2[x];h2[x]=tot2;}void MCS(){for (int i=1;i<=n;i++)Add(0,i);for (int j=n;j;j--){while (1){int x=0;for (int i=h2[best];i;i=e2[i].ne){if (!v[e2[i].y]) {x=e2[i].y;break;}else h2[best]=e2[i].ne;}if (x){v[x]=1;seq[j]=x;for (int i=h[x];i;i=e[i].ne)if (!v[e[i].y]){int y=e[i].y;label[y]++;Add(label[y],y);best=max(best,label[y]);}break;}else best--;}}}int main(){ans=0; scanf("%d%d",&n,&m);for (int i=1;i<=n;i++)v[i]=0;for (int i=1;i<=m;i++){int x,y;scanf("%d%d",&x,&y);Addedge(x,y);Addedge(y,x);}MCS();for (int j=n;j;j--){int x=seq[j];for (int i=h[x];i;i=e[i].ne)mark[c[e[i].y]]=j;for (int i=1;i<=n;i++)if (mark[i]!=j) {c[x]=i;ans=max(i,ans);break;}}printf("%d\n",ans);return 0;}
Perception:
1. It is said that the minimum staining is an NP problem. Why can't we simply use the DFS staining ??? Very confused .. ..
[Bzoj 1006] [hnoi2008] A magical country