CodeForces 412D Giving Awards
根据给出的条件建边,然后进行dfs
对于某个点x,当x的后继都遍历完毕后,再输出x节点。
这样能保证所有约束条件。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std; const int maxn=+;
int n,m;
vector<int>g[maxn];
int flag[maxn]; void dfs(int x)
{
flag[x]=;
for(int i=;i<g[x].size();i++)
{
if(flag[g[x][i]]==) continue;
dfs(g[x][i]);
}printf("%d ",x);
} int main()
{
scanf("%d%d",&n,&m);
memset(flag,,sizeof flag);
for(int i=;i<=m;i++)
{
int u,v; scanf("%d%d",&u,&v);
g[u].push_back(v);
} for(int i=;i<=n;i++) if(flag[i]==) dfs(i);
printf("\n");
return ;
}
CodeForces 412D Giving Awards的更多相关文章
- Codeforces D. Giving Awards 412 题解
就是依照一定顺序输出排序. 比方a欠b的钱就不能先输出a然后输出b. 本题的技巧就是.要求的是不能先输出a然后输出b,可是能够先输出b然后输出a. 故此能够依照a欠b的钱的关系.建立图,然后DFS深度 ...
- Coder-Strike 2014 - Round 1 D. Giving Awards
题目的意思是 老板给n个人发工资,x欠y的工资,the joy of person x from his brand new money reward will be much less, 老板想避免 ...
- Coder-Strike 2014 - Round 1(A~E)
题目链接 A. Poster time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inputou ...
- Codeforces 873E Awards For Contestants ST表
原文链接https://www.cnblogs.com/zhouzhendong/p/9255885.html 题目传送门 - CF873E 题意 现在要给 $n(n\leq 3000)$ 个学生颁奖 ...
- Codeforces Round #284 (Div. 2)A B C 模拟 数学
A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces Hill Number 数位dp
http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits: 5000 MS Memory Limits: ...
- Codeforces 714C. Sonya and Queries Tire树
C. Sonya and Queries time limit per test:1 second memory limit per test: 256 megabytes input:standar ...
- Codeforces Round #284 (Div. 2)
题目链接:http://codeforces.com/contest/499 A. Watching a movie You have decided to watch the best moment ...
- Codeforces Round #340 (Div. 2) C. Watering Flowers 暴力
C. Watering Flowers 题目连接: http://www.codeforces.com/contest/617/problem/C Descriptionww.co A flowerb ...
随机推荐
- PDO对象
<?php //造DSN:驱动名:dbname=数据库名;host=服务器地址 $dsn = "mysql:dbname=mydb;host=localhost"; //造P ...
- 201312月CCF-2,ISBN号码分析
明天要考CCF啦,偶还是很紧张的.最近看了数据结构,今天才开始上机练习,对,我就是这么懒..废话不多说,我写这篇文章主要是分析CCF编程的小窍门,因为在网上没找到,所以我决定自力更生丰衣足食.!!!! ...
- stm32时钟配置总结
stm32时钟配置时钟源: 1,HSE(高速外部时钟)即常见的外接8M晶振方案: 2,HSI(高速内部时钟) 即8M内部振荡时钟方案: 3,LSE(低速外部时钟)即常见的32.768Khz晶振方案: ...
- TortoiseGit保存用户名及密码
保存密码方式如下,需要setting中填写自己的名字,Email地址,并在.gitconfig中 [credential] 中设置helper = store
- div盒子水平垂直居中的方法
这个问题比较老,方法比较多,各有优劣,着情使用. 一.盒子没有固定的宽和高 方案1.Transforms 变形 这是最简单的方法,不仅能实现绝对居中同样的效果,也支持联合可变高度方式使用.内容块定义t ...
- bootstraptable表格基本
function tableint(){ $("#tableFromData").bootstrapTable({ url:BASE_URL+"/do/fron ...
- android 实践项目
电子词典 http://files.cnblogs.com/blogLYF/lyf_danci.apk
- RPC框架基本原理(一):服务注册
什么是RPC框架 RPC整个过程涉及四类对象:客户端.客户端代理.服务端和服务端代理.RPC要求客户端和服务端之间约定好调用接口和传输格式(如JSON,Xml等),客户端在调用该接口时,由客户端的代理 ...
- linux上安装配置samba服务器
linux上安装配置samba服务器 在linux上安装配置samba服务器 在这给大家介绍一个不错的家伙,samba服务.如果您正在犯愁,如何在Windows和Linux之间实现资源共享,就请看看这 ...
- hdu_4529_郑厂长系列故事——N骑士问题(状压DP)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=4529 题意:中文,不解释 题解:状压DP,dp[i][j][k][s]表示第i行当前用了j个骑士,i- ...