Codeforces Round #550 (Div. 3) F. Graph Without Long Directed Paths (二分图染色)
题意:有\(n\)个点和\(m\)条无向边,现在让你给你这\(m\)条边赋方向,但是要满足任意一条边的路径都不能大于\(1\),问是否有满足条件的构造方向,如果有,输出一个二进制串,表示所给的边的方向.
题解:我们先单独拿出\(3\)个点来看,选择一个点,那么与它相连的另外两个点到自己的方向一定是相同的,同理,我们可以推广到任意一个点,与它相连的所有点到它的方向必须都是一样的才行,其实到这儿就不难看出可以用二分图染色来写了,然后打个板子就能很愉快的AC啦~
代码:
int n,m;
int a,b;
vector<int> v[N];
int color[N];
PII edge[N]; bool dfs(int u,int c){
color[u]=c; for(auto w:v[u]){
if(!color[w]){
if(!dfs(w,3-c)) return false;
}
else{
if(color[w]==c) return false;
}
}
return true;
} int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>m; rep(i,1,m){
cin>>a>>b;
edge[i].fi=a;
edge[i].se=b;
v[a].pb(b);
v[b].pb(a);
} bool flag=true; if(!dfs(1,1)){
flag=false;
} if(!flag) cout<<"NO\n";
else{
cout<<"YES\n";
rep(i,1,m){
int x=edge[i].fi;
int y=edge[i].se;
if(color[x]==1 && color[y]==2) cout<<1;
else cout<<0;
}
} return 0;
}
Codeforces Round #550 (Div. 3) F. Graph Without Long Directed Paths (二分图染色)的更多相关文章
- Codeforces Round #550 (Div. 3) F. Graph Without Long Directed Paths
F. Graph Without Long Directed Paths time limit per test 2 seconds memory limit per test 256 ...
- Codeforces Round #496 (Div. 3) F - Berland and the Shortest Paths
F - Berland and the Shortest Paths 思路:还是很好想的,处理出来最短路径图,然后搜k个就好啦. #include<bits/stdc++.h> #defi ...
- F. Graph Without Long Directed Paths Codeforces Round #550 (Div. 3)
F. Graph Without Long Directed Paths time limit per test 2 seconds memory limit per test 256 megabyt ...
- Codeforces Round #485 (Div. 2) F. AND Graph
Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...
- Codeforces Round #486 (Div. 3) F. Rain and Umbrellas
Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...
- Codeforces Round #501 (Div. 3) F. Bracket Substring
题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...
- Codeforces Round #499 (Div. 1) F. Tree
Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...
- CodeForces Round #550 Div.3
http://codeforces.com/contest/1144 A. Diverse Strings A string is called diverse if it contains cons ...
- Codeforces Round #375 (Div. 2) F. st-Spanning Tree 生成树
F. st-Spanning Tree 题目连接: http://codeforces.com/contest/723/problem/F Description You are given an u ...
随机推荐
- Openstack OCATA 安装环境说明(一) 未完成版本
1 Openstack简介: 2 实验说明: 3 图例: 4 实验环境说明: 4.1 ) 网卡说明: 网卡名 网 段 连接方式 说明 eth0 10.10.5.0/24 仅主机网络 内部网络自动以IP ...
- wpf 中用 C# 代码创建 PropertyPath ,以对间接目标进行 Storyboard 动画.
如图,一个 Rectangle 一个 Button ,点击按钮时要通过动画完成对 Rectangle填充色的渐变动画. Xaml: 1 <Window 2 x:Class="WpfAp ...
- iTerm2 实现 ssh 自动登录,并使用 Zmodem 实现快速传输文件
原文链接:https://fuckcloudnative.io/posts/iterm2-auto-login/ 对于 YAML 工程师来说,我们经常需要 ssh 登录不同的服务器,每次登录时都要经历 ...
- [分享] 最流行的 10 个 JavaScript 库
1. Lodash https://github.com/lodash/lodash 一个工具库,用得还蛮多. 2. Chalk https://github.com/chalk/chalk 给终端加 ...
- QT串口助手(二):参数配置
作者:zzssdd2 E-mail:zzssdd2@foxmail.com 一.前言 主要实现功能 串口参数的配置:波特率.数据位.停止位.校验位 本机串口设备的查询与添加显示 串口设备的手动更新与打 ...
- 安装JDK与卸载JDK教程
卸载JDK 删除JDK的安装目录,也就是删除了主程序(通过环境变量可以找到) 删除java_home的环境变量 删除环境变量path中与java_home相关的 通过DOS命令cmd来检验是否卸载成功 ...
- C#高级编程第11版 - 第五章 索引
[1]5.1 泛型概述 1.通过泛型,你可以创建独立于特定类型(contained types)以外的方法和类,而不用为不同类型编写多份同样功能的代码,你只需要创建一个方法或者类. 2.泛型类使用泛型 ...
- 基于Vue的npm组件库
前言(*❦ω❦) 思维导图可能有点高糊,有点太大了,项目和导图文件放到github或giteee上,这个思维导图也是我文章的架构,思维导图是用FeHelper插件生成的,这个是一款开源chrome插件 ...
- 浅析Linux进程空间布局
一.进程空间分布概述 对于一个进程,其空间分布如下图所示: 1.参数说明 程序段(Text):程序代码在内存中的映射,存放函数体的二进制代码. 初始化过的数据(Data):在程序运行初已经对变量进行初 ...
- 将HDFS中指定文件的内容输出到终端。
1 import java.io.*; 2 import org.apache.hadoop.conf.Configuration; 3 import org.apache.hadoop.fs.*; ...