zoukankan      html  css  js  c++  java
  • [BZOJ]1116: [POI2008]CLO

    题解:  有个显然的结论  如果能成环  那么必然能让环上的点都满足条件 然后 与这个环联通的点必然也都能满足要求 所以问题转化成 对于每个联通块里面边的个数是否都大于点的个数  并查集维护即可

    #include <algorithm>
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <stack>
    #include <queue>
    #include <cmath>
    #include <set>
    #include <map>
    #define mp make_pair
    #define pb push_back
    #define pii pair<int,int>
    #define link(x) for(edge *j=h[x];j;j=j->next)
    #define inc(i,l,r) for(int i=l;i<=r;i++)
    #define dec(i,r,l) for(int i=r;i>=l;i--)
    const int MAXN=3e5+10;
    const double eps=1e-8;
    #define ll long long
    using namespace std;
    struct edge{int t,v;edge*next;}e[MAXN<<1],*h[MAXN],*o=e;
    void add(int x,int y,int vul){o->t=y;o->v=vul;o->next=h[x];h[x]=o++;}
    ll read(){
        ll x=0,f=1;char ch=getchar();
        while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
        while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
        return x*f;
    }
    
    
    int f[MAXN];
    int find1(int x){
        if(x==f[x])return x;
        return f[x]=find1(f[x]);
    }
    
    int sz[MAXN],tag[MAXN];
    
    int main(){
        int n=read();int m=read();
        inc(i,1,n)f[i]=i,sz[i]=1;
        int u,v;
        inc(i,1,m){
    	u=read();v=read();
    	int t1=find1(u);int t2=find1(v);
    	if(t1==t2){tag[t1]++;continue;}
    	f[t1]=t2;sz[t2]+=sz[t1];tag[t2]+=(tag[t1]+1);
        }
        inc(i,1,n){
    	int t1=find1(i);
    	if(tag[t1]>=sz[t1])continue;
    	printf("NIE
    ");
    	return 0;
        }
        printf("TAK
    ");
        return 0;
    }
    

      

    1116: [POI2008]CLO

    Time Limit: 10 Sec  Memory Limit: 162 MB
    Submit: 1464  Solved: 795
    [Submit][Status][Discuss]

    Description

    Byteotia城市有n个 towns m条双向roads. 每条 road 连接 两个不同的 towns ,没有重复的road. 你要把其中一些road变成单向边使得:每个town都有且只有一个入度

    Input

    第一行输入n m.1 <= n<= 100000,1 <= m <= 200000 下面M行用于描述M条边.

    Output

    TAK或者NIE 常做POI的同学,应该知道这两个单词的了...

    Sample Input

    4 5
    1 2
    2 3
    1 3
    3 4
    1 4

    Sample Output

    TAK

    上图给出了一种连接方式.
  • 相关阅读:
    84. Largest Rectangle in Histogram (Solution 2)
    84. Largest Rectangle in Histogram (Solution 1)
    73. Set Matrix Zeroes
    【JavaScript】Symbol 静态方法
    【JavaScript】Date
    【JavaScript】Math
    725. Split Linked List in Parts把链表分成长度不超过1的若干部分
    791. Custom Sort String字符串保持字母一样,位置可以变
    508. Most Frequent Subtree Sum 最频繁的子树和
    762. Prime Number of Set Bits in Binary Representation二进制中有质数个1的数量
  • 原文地址:https://www.cnblogs.com/wang9897/p/10343887.html
Copyright © 2011-2022 走看看