#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,思维)的更多相关文章

  1. Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序

    Educational Codeforces Round 72 (Rated for Div. 2)-D. Coloring Edges-拓扑排序 [Problem Description] ​ 给你 ...

  2. 拓扑排序入门详解&&Educational Codeforces Round 72 (Rated for Div. 2)-----D

    https://codeforces.com/contest/1217 D:给定一个有向图,给图染色,使图中的环不只由一种颜色构成,输出每一条边的颜色 不成环的边全部用1染色 ps:最后输出需要注意, ...

  3. Educational Codeforces Round 72 (Rated for Div. 2)

    https://www.cnblogs.com/31415926535x/p/11601964.html 这场只做了前四道,,感觉学到的东西也很多,,最后两道数据结构的题没有补... A. Creat ...

  4. 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 ...

  5. Educational Codeforces Round 72 (Rated for Div. 2) B题

    Problem Description: You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a ...

  6. 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 ...

  7. Coloring Edges(有向图环染色)-- Educational Codeforces Round 72 (Rated for Div. 2)

    题意:https://codeforc.es/contest/1217/problem/D 给你一个有向图,要求一个循环里不能有相同颜色的边,问你最小要几种颜色染色,怎么染色? 思路: 如果没有环,那 ...

  8. 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 ...

  9. Educational Codeforces Round 72 (Rated for Div. 2)E(线段树,思维)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;#define BUF_SIZE 100000 ...

  10. 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 ...

随机推荐

  1. 发现一个比较好玩的,git的仓库可以转换

    我们通过 git clone 下载一个仓库到本地, 1.这个本地的文件夹名字可以随便改. 2.如果你把本地仓库的全部文件,剪切到另一个文件夹内,这个新的文件夹就是git的本地仓库.

  2. 查看Oracle的表中有哪些索引(用user_indexes和user_ind_columns)

    用user_indexes和user_ind_columns系统表查看已经存在的索引 对于系统中已经存在的索引我们可以通过以下的两个系统视图(user_indexes和user_ind_columns ...

  3. sqlmap 扫描注入漏洞

    .检测是否存在漏洞: sqlmap -u .获取数据库信息: sqlmap -u --dbs .数据库表信息: sqlmap -u -D security --tables .表中字段信息 sqlma ...

  4. tp5 自定义公共函数,前台模板调用

    最近用tp5做一个cms,在添加模型的时候,选择类型,这类型太多了,如果一个个的去判断显示,能累死人了,干脆写个公共方法, 首先写公共方法用到Common.php,目录project/applicat ...

  5. hybird怎么实现的(核心webview)

    链接:https://blog.csdn.net/gongch0604/article/details/80510005

  6. 技术学习的网站 http://www.runoob.com/

    菜鸟教程:http://www.runoob.com/ W3C:https://www.w3cschool.cn/tutorial 脚本之家:https://www.jb51.net/

  7. 为什么局部内部类和匿名内部类只能访问 final 的局部变量?

    首先,我们看一个局部内部类的例子: class OutClass { private int age = 12; public void outPrint(final int x) { class I ...

  8. IDEA导入maven项目不自动识别

    解决办法: 选中module的pom.xml,右键,选择" add as maven project",即可刷新为maven项目

  9. C:变量的声明与定义

    声明变量不需要建立存储空间,如:extern int a; 定义变量需要建立存储空间,如:int b; #include <stdio.h> int main() { //extern 关 ...

  10. HDU5444 Elven Postman

    按要求递归建树输出~ #include<cstdio> #include<algorithm> #include<cstring> using namespace ...