[题目链接]

http://codeforces.com/contest/623/problem/A

[算法]

首先 , 所有与其他节点都有连边的节点需标号为'b'

然后 , 我们任选一个节点 , 将其标号为'a' , 然后标记所以该节点能到达的节点

最后 , 我们需要检查这张图是否合法 , 只需枚举两个节点 , 若这两个节点均为'a'或'c' , 那么 , 若两个节点标号不同但有连边 , 不合法 , 如果两个节点标号相同但没有连边 , 也不合法

时间复杂度 : O(N ^ 2)

[代码]

#include<bits/stdc++.h>
using namespace std;
#define MAXN 510 struct edge
{
int to , nxt;
} e[MAXN * MAXN * ]; int tot , n , m;
int deg[MAXN],q[MAXN],head[MAXN];
char ans[MAXN];
bool finished[MAXN];
bool g[MAXN][MAXN]; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
inline void addedge(int u,int v)
{
tot++;
e[tot] = (edge){v,head[u]};
head[u] = tot;
} int main()
{ read(n); read(m);
for (int i = ; i <= m; i++)
{
int u , v;
read(u); read(v);
deg[u]++; deg[v]++;
addedge(u,v);
addedge(v,u);
g[u][v] = g[v][u] = true;
}
for (int i = ; i <= n; i++)
{
if (deg[i] == n - )
{
ans[i] = 'b';
finished[i] = true;
}
}
int l = , r = ;
for (int i = ; i <= n; i++)
{
if (!finished[i])
{
ans[i] = 'a';
finished[i] = true;
q[++r] = i;
break;
}
}
while (l <= r)
{
int cur = q[l++];
for (int i = head[cur]; i; i = e[i].nxt)
{
int v = e[i].to;
if (!finished[v])
{
finished[v] = true;
ans[v] = 'a';
q[++r] = v;
}
}
}
for (int i = ; i <= n; i++)
{
if (!finished[i])
ans[i] = 'c';
}
for (int i = ; i <= n; i++)
{
if (ans[i] == 'b') continue;
for (int j = ; j <= n; j++)
{
if (i == j || ans[j] == 'b') continue;
if (ans[i] == ans[j] && !g[i][j])
{
printf("No\n");
return ;
}
if (ans[i] != ans[j] && g[i][j])
{
printf("No\n");
return ;
}
}
}
printf("Yes\n");
for (int i = ; i <= n; i++) printf("%c",ans[i]);
printf("\n"); return ; }

[Codeforces 623A] Graph and String的更多相关文章

  1. codeforces 623A. Graph and String 构造

    题目链接 给出一个图, 每个节点只有三种情况, a,b, c. a能和a, b连边, b能和a, b, c,连边, c能和b, c连边, 且无重边以及自环.给出初始的连边情况, 判断这个图是否满足条件 ...

  2. codeforces 624C Graph and String

    C. Graph and String time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. AIM Tech Round (Div. 2) C. Graph and String 二分图染色

    C. Graph and String 题目连接: http://codeforces.com/contest/624/problem/C Description One day student Va ...

  4. 图论:(Code Forces) Graph and String

    Graph and String time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  5. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  6. AIM Tech Round (Div. 2) C. Graph and String

    C. Graph and String time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. 【CodeForces 624C】Graph and String

    题 题意 n个表示abc三个字符的点,所有a和b是相连的,所有b和c是相连的,所有相同的是相连的,现在给你n个点和他们之间的m条边,判断是否存在这样的字符串,存在则给出一个符合条件的. 分析 我的做法 ...

  8. 【动态规划】【最短路】Codeforces 710E Generate a String

    题目链接: http://codeforces.com/problemset/problem/710/E 题目大意: 问写N个字符的最小花费,写一个字符或者删除一个字符花费A,将当前的字符数量翻倍花费 ...

  9. codeforces 632C The Smallest String Concatenation

    The Smallest String Concatenation 题目链接:http://codeforces.com/problemset/problem/632/C ——每天在线,欢迎留言谈论. ...

随机推荐

  1. html页面加载初始化方法

    js: 方法一: window.onload=function(){内容} 方法二(自己定义方法): function onload(){内容} onload(); jQuery: 方法一: $(do ...

  2. C++标准模板库 ——堆栈使用

    include using namespace std; stack S; S.push(i); S.pop(); int x = S.top(); ```

  3. wps填充1到1000

    A1单元格1 ,选中,填充,序列,确定

  4. Java语言编写TPL语言词法分析器

    程序实现原理: 将TXT文本中的数据读出,并按照其类别的不同,将关键字.数字以及运算符识别出来. 一.词法分析实验步骤 1. 熟悉TPL语言 2. 编写TPL语言程序,至少3个,一个简单,一个复杂的( ...

  5. android开发里跳过的坑——button不响应点击事件

    昨天遇到一个头疼的问题,在手机上按钮事件都很正常,但是在平板上(横屏显示的状态),button点击事件不响应,代码简化如下: public class Test extends Activity im ...

  6. msp430入门编程03

    msp430的C标识符和关键字 msp430入门学习 msp430入门编程

  7. 逆袭指数-——杭电校赛(dfs)

    逆袭指数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  8. SecurityContextHolder.getContext().getAuthentication()为null的情况

    原理: UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication() . ...

  9. SQL PATINDEX检索

    语法格式:PATINDEX ( '%pattern%' , expression ) 返回pattern字符串在表达式expression里第一次出现的位置,起始值从1开始算. pattern字符串在 ...

  10. maven提示“编码 GBK 的不可映射字符”问题的解决

    pom.xml中加上如下代码 <properties> <!-- spring版本号 --> <spring.version>4.2.3.RELEASE</s ...