• [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

    上图给出了一种连接方式.
  • 相关阅读:
    如何选择数据科学最好的Python IDE?
    Python代码详解:入门时间序列分类
    2月编程语言排行榜:Python 稳坐前三,Java依旧第一
    写 Python 时的 5 个坏习惯
    Python的多线程threading和多进程multiprocessing
    Python看春运,万条拼车数据背后的春节迁徙地图
    python数据分析案例实战——融360客户贷款风险预测(信用卡)
    情人节攻略:用Python撒狗粮的正确姿势
    Python函数式编程
    python基础
  • 原文地址:https://www.cnblogs.com/wang9897/p/10343887.html
Copyright © 2020-2023  润新知