Educational Codeforces Round 72 (Rated for Div. 2)D(DFS,思维)
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int n,m,k=1;
int c[5007],vis[5007];
vector<int>v[5007],no[5007];
void dfs(int u){
vis[u]=-1;
for(int i=0;i<v[u].size();++i){
int t=v[u][i];
int x=no[u][i];
if(vis[t]==-1){//反向边用另一种颜色染
k=2;
c[x]=2;
}
else if(!vis[t])
dfs(t);
}
vis[u]=1;
}
int main(){
cin>>n>>m;
for(int i=1;i<=m;++i){
int x,y;
cin>>x>>y;
v[x].push_back(y);
no[x].push_back(i);
}
for(int i=1;i<=n;++i)
if(!vis[i])
dfs(i);
cout<<k<<"\n";
for(int i=1;i<=m;++i)
if(c[i]==2)
cout<<2<<" ";
else
cout<<1<<" ";
return 0;
}
Educational Codeforces Round 72 (Rated for Div. 2)D(DFS,思维)的更多相关文章
- Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序
Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序 [Problem Description] 给你 ...
- 拓扑排序入门详解&&Educational Codeforces Round 72 (Rated for Div. 2)-----D
https://codeforces.com/contest/1217 D:给定一个有向图,给图染色,使图中的环不只由一种颜色构成,输出每一条边的颜色 不成环的边全部用1染色 ps:最后输出需要注意, ...
- Educational Codeforces Round 72 (Rated for Div. 2)
https://www.cnblogs.com/31415926535x/p/11601964.html 这场只做了前四道,,感觉学到的东西也很多,,最后两道数据结构的题没有补... A. Creat ...
- Educational Codeforces Round 72 (Rated for Div. 2) C题
C. The Number Of Good Substrings Problem Description: You are given a binary string s (recall that a ...
- Educational Codeforces Round 72 (Rated for Div. 2) B题
Problem Description: You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a ...
- Educational Codeforces Round 72 (Rated for Div. 2) A题
Problem Description: You play your favourite game yet another time. You chose the character you didn ...
- Coloring Edges(有向图环染色)-- Educational Codeforces Round 72 (Rated for Div. 2)
题意:https://codeforc.es/contest/1217/problem/D 给你一个有向图,要求一个循环里不能有相同颜色的边,问你最小要几种颜色染色,怎么染色? 思路: 如果没有环,那 ...
- Educational Codeforces Round 72 (Rated for Div. 2) Solution
传送门 A. Creating a Character 设读入的数据分别为 $a,b,c$ 对于一种合法的分配,设分了 $x$ 给 $a$ 那么有 $a+x>b+(c-x)$,整理得到 $x&g ...
- Educational Codeforces Round 72 (Rated for Div. 2)E(线段树,思维)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;#define BUF_SIZE 100000 ...
- Educational Codeforces Round 72 (Rated for Div. 2)C(暴力)
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;char s[200007];int a[20 ...
随机推荐
- h5页面调用相机功能
//accept:表示要打开的文件类型 capture:表示可以捕获到系统默认的设备 <input type="file" accept="image/*" ...
- 一组关于{x}的积分
\[\Large\displaystyle \int_{0}^{1}\left \{ \frac{1}{x} \right \}\mathrm{d}x~,~\int_{0}^{1}\left \{ \ ...
- layui-表格宽度自适应
不设置表格宽度,表格默认全屏 可以通过以下方式设置表格宽度
- php自动读取文件夹下所有图片
$path = 'xxxxx';///当前目录$handle = opendir($path); //当前目录while (false !== ($file = readdir($handle))) ...
- firefox插件hostadmin自由切换host
在Mac下firefox插件hostadmin切换host,遇到的第一个问题就是提示权限不足,解决办法,在终端输入以下命令即可: sudo chmod og+w /etc/hosts chmod修改权 ...
- python练习:编写一个函数isIn,接受两个字符串作为参数,如果一个字符串是另一个字符串的一部分,返回True,否则返回False。
python练习:编写一个函数isIn,接受两个字符串作为参数,如果一个字符串是另一个字符串的一部分,返回True,否则返回False. 重难点:定义函数的方法.使用str类型的find()函数,可以 ...
- ASP.NET Core搭建多层网站架构【14-扩展之部署到IIS】
2020/02/03, ASP.NET Core 3.1, VS2019, IIS 10, dotnet-hosting-3.1.1-win.exe 摘要:基于ASP.NET Core 3.1 Web ...
- 在Linux系统中使用ntfs、fat32格式的存储设备
在Linux系统中使用ntfs.fat32格式的存储设备 我们通常使用的移动硬盘或U盘一般都是ntfs或fat32的文件系统,作为一名运维工程师,经常会遇到把移动硬盘或者U盘上的内容拷贝的Linu ...
- R - Fence Repair POJ - 3253
Farmer John wants to repair a small length of the fence around the pasture. He measures the fence an ...
- ES-基本操作
(1)创建索引 put 192.168.247.197:9200/type2 /type2 (2)创建映射 post 192.168.247.197:9200/type2/type/_mapping ...