zoukankan      html  css  js  c++  java
  • BZOJ1116 [POI2008]CLO

    很像SCOI的游戏(其实基本就是一样)

    首先我们可以推出一个性质,当且仅当某一个连通块中没有环存在输出NIE(无解的意思)

    因为有环的话。。。就可以构造一棵基环外向树

    所以做法就和SCOI的游戏很像了,并查集维护即可。

     1 /**************************************************************
     2     Problem: 1116
     3     User: rausen
     4     Language: C++
     5     Result: Accepted
     6     Time:252 ms
     7     Memory:1292 kb
     8 ****************************************************************/
     9  
    10 #include <cstdio>
    11  
    12 using namespace std;
    13 const int N = 100005;
    14 int n, m, fa[N];
    15 bool vis[N];
    16  
    17 inline int read(){
    18     int x = 0;
    19     char ch = getchar();
    20     while (ch < '0' || ch > '9')
    21         ch = getchar();
    22     while (ch >= '0' && ch <= '9'){
    23         x = x * 10 + ch - '0';
    24         ch = getchar();
    25     }
    26     return x;
    27 }
    28  
    29 int find_fa(const int x){
    30     return x == fa[x] ? x : fa[x] = find_fa(fa[x]);
    31 }
    32  
    33 int main(){
    34     int i, x, y;
    35     n = read(), m = read();
    36     for (i = 1; i <= n; ++i)
    37         fa[i] = i;
    38     for (i = 1; i <= m; ++i){
    39         x = find_fa(read());
    40         y = find_fa(read());
    41         if (x != y){
    42             fa[x] = y;
    43             vis[y] |= vis[x];
    44         } else vis[x] = 1;
    45     }
    46     for (i = 1; i <= n; ++i)
    47         if (!vis[find_fa(i)]){
    48             puts("NIE");
    49             return 0;
    50         }
    51     puts("TAK");
    52     return 0;
    53 }
    View Code
    By Xs酱~ 转载请说明 博客地址:http://www.cnblogs.com/rausen
  • 相关阅读:
    在Wince下使用钩子函数
    WinCE下钩子应用(一)——WinCE 下实时捕获键盘消息
    记录此刻
    常用数列
    百度之星度度熊拼三角
    笛卡尔定理
    Lucas定理
    简单概念
    Unknown Treasure Lucas+中国剩余定理+快速乘
    2017ccpc杭州站 Problem B. Master of Phi
  • 原文地址:https://www.cnblogs.com/rausen/p/4074567.html
Copyright © 2011-2022 走看看