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 ...
随机推荐
- jquery 获取 父级 iframe 里的控件对象
window.parent.document.getElementsByTagName('iframe')[0].contentWindow.document.getElementById('id')
- Python 报错 AttributeError: module 'django.db.models' has no attribute 'SubfieldBase'
AttributeError: module 'django.db.models' has no attribute 'SubfieldBase' http://www.guanggua.com/qu ...
- JAVA基础学习(6)之使用对象
6使用对象 6.1字符类型 6.1.1字符类型 char和int互相转换 //a比A大32 Scanner in=new Scanner(System.in); char c='B'; char c1 ...
- Jmeter_JsonPath 提取器
1.登录老黄历 2.提取阳历的数据,不用正则表达式提取器,因为这里是字典形式,用Json path提取器更简单 3.把提取的数据放到百度里去发送请求 4. 5. 6. 7. 8. 9.
- 设计模式开始--UML类之间关系表示
平常写代码写的比较多,没有从架构的层次了解类与类之间的关系,下面就从代码的层面论述UML中类与类质之间的关系 实线的关系要强于虚线 1.extends 表示继承 2.implements表示实现 3. ...
- MySQL基本查询
1.查询某数据库中表的总数 select count(*) from information_schema.tables where table_schema='dbname'; 2.仅占一列显示某数 ...
- MySQL忘记密码(终极解决方法,亲测有效,windows版本)
1.进入mysql的bin目录 2.net stop mysql 3.mysqld --skip-grant-tables 输入 mysqld --skip-grant-tables 回车. (--s ...
- mui 获取本地APP本版号的两种方式
第一种 mui.plusReady(function () { mui.getJSON("manifest.json", null, function (data) { vum = ...
- vue动态加载jQuery插件
要先npm安装jQuery插件哦 window.$=$; window.jQuery=$; function loadJs(Url,callback){ var Nscript=document.cr ...
- js中this,箭头函数和普通函数
四种基本用法 1. 一般方法中,this代指全局对象 window 2. 作为对象方法调用,this代指当前对象 3. 作为构造函数调用,this 指代new 出的对象 function test() ...