CF623A Graph and String

Posted gzygzy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF623A Graph and String相关的知识,希望对你有一定的参考价值。

CF623A Graph and String

休闲的题目.
WA了5次,hack数据爽的一批.
考虑补图.
显然,补图中,出度为0的点是B.
然后二分图染色.
如果不是二分图,就输出"No"
染完色后,看看是否满足数据即可
写的太丑了,捂脸.

/*header*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i , x, p) for(int i = x;i <= p;++ i)
#define sep(i , x, p) for(int i = x;i >= p;-- i)
#define gc getchar()
#define pc putchar
#define ll long long
#define mk make_pair
#define fi first
#define se second
using std::min;
using std::max;
using std::swap;
const int maxN = 500 + 7;

inline int gi() {
    int x = 0,f = 1;char c = gc;
    while(c < '0' || c > '9') {if(c == '-')f = -1;c = gc;}
    while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = gc;}return x * f;
}

void print(int x) {
    if(x < 0) pc('-') , x = -x;
    if(x >= 10) print(x / 10);
    pc(x % 10 + '0');
}

int n , m , dis[maxN][maxN], col[maxN];
bool flag;

void dfs(int now , int cl) {
    col[now] = cl;
    rep(i , 1, n) {
        int v = i;
        if(!dis[now][v]) continue;
        if(col[v] == col[now]) {
            puts("No");
            exit(0);
        }
        if(!col[v]) dfs(v , 3 - cl);
    }
}

int main() {
    n = gi();m = gi();
    rep(i , 1, n) rep(j , 1, n) dis[i][j] = 1;
    rep(i , 1, n) dis[i][i] = 0;
    while(m --) {
        int u = gi() , v = gi();
        dis[v][u] = dis[u][v] = 0;
    }
    int B = 0;bool fl = false;
    for(int i = 1;i <= n;++ i) {
        B = i;
        for(int j = 1;j <= n;++ j) 
            if(dis[i][j]) fl = true;
        if(fl) break;
    }
    if(fl) dfs(B , 1);
    rep(i , 1, n) {
        rep(j , 1, i - 1) {
            if(!dis[i][j]) {
                if(col[i] + col[j] == 3) {
                    puts("No");return 0;
                    }
                }
            }
        }
        rep(i , 1, n) {
            if(col[i] == 0) {
                rep(j , 1, n) {
                    if(dis[i][j]) {
                        puts("No");return 0;
                    }
                }
            }
        }
    puts("Yes");
    for(int i = 1;i <= n;++ i) {
        if(col[i] == 0) pc('b');
        if(col[i] == 1) pc('a');
        if(col[i] == 2) pc('c');
    }
    return 0;
}

以上是关于CF623A Graph and String的主要内容,如果未能解决你的问题,请参考以下文章

cf623A. Graph and String(二分图 构造)

CF1082G Petya and Graph

CF459E Pashmak and Graph

CF 990D Graph And Its Complement 第十八 构造思维

cf916CJamie and Interesting Graph

CF916C Jamie and Interesting Graph