根据给出的条件建边,然后进行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的更多相关文章

  1. Codeforces D. Giving Awards 412 题解

    就是依照一定顺序输出排序. 比方a欠b的钱就不能先输出a然后输出b. 本题的技巧就是.要求的是不能先输出a然后输出b,可是能够先输出b然后输出a. 故此能够依照a欠b的钱的关系.建立图,然后DFS深度 ...

  2. 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, 老板想避免 ...

  3. Coder-Strike 2014 - Round 1(A~E)

    题目链接 A. Poster time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inputou ...

  4. Codeforces 873E Awards For Contestants ST表

    原文链接https://www.cnblogs.com/zhouzhendong/p/9255885.html 题目传送门 - CF873E 题意 现在要给 $n(n\leq 3000)$ 个学生颁奖 ...

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

  6. codeforces Hill Number 数位dp

    http://www.codeforces.com/gym/100827/attachments Hill Number Time Limits:  5000 MS   Memory Limits: ...

  7. Codeforces 714C. Sonya and Queries Tire树

    C. Sonya and Queries time limit per test:1 second memory limit per test: 256 megabytes input:standar ...

  8. Codeforces Round #284 (Div. 2)

    题目链接:http://codeforces.com/contest/499 A. Watching a movie You have decided to watch the best moment ...

  9. Codeforces Round #340 (Div. 2) C. Watering Flowers 暴力

    C. Watering Flowers 题目连接: http://www.codeforces.com/contest/617/problem/C Descriptionww.co A flowerb ...

随机推荐

  1. Excel补全日期(日期按顺序补全)

    1.给出的数据 2.想补全缺失的日期,比如2015/3/1,2015/3/2,... 1)在D列输入完整的日期,如下图所示: 2)在E2处写函数“=IF(ISERR(VLOOKUP(D2,B:C,2, ...

  2. knockout.js-创建视图模型

    监控属性(Observables) knockout的三个核心特点: 1.监控属性与依赖跟踪 2.声明式绑定 3.模板 本页,你将学习上述三个特性.但是在这之前,先了解一下MVVC模式,及 视图模型( ...

  3. html5学习(三)

    html5特点: 1 微数据与微格式等方面的支持. 2 本地存储,离线应用. 3 API调用,地图,位置,LBS等. 4 连接通讯,后台线程. 5 多媒体. 7 css3.

  4. Xcode8.2 继续使用插件

    网上参考了文章:http://www.jianshu.com/p/ab819babf2c3 使用的是:update_xcode_plugins . 但要注意的是,在Xcode 8.2下安装,并没有给我 ...

  5. selenium C#下的zencart自动化测试(WFloginUrlPayment)环境4.0

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  6. js 输出HTML 样式

    document.write("<div style='width: 100px;height: 100px;background-color: greenyellow;'>Th ...

  7. Boxes in a Line(移动盒子)

      You have n boxes in a line on the table numbered 1 . . . n from left to right. Your task is to sim ...

  8. HDU2539:点球大战

    Problem Description 在足球比赛中,有不少赛事,例如世界杯淘汰赛和欧洲冠军联赛淘汰赛中,当比赛双方经过正规比赛和加时赛之后仍然不分胜负时,需要进行点球大战来决定谁能够获得最终的胜利. ...

  9. 自定义 IP 地址

    可以在安装的时候,点击网络配置 1.修改网卡配置 编辑:vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 #描述网卡对应的设备别名,例如 ...

  10. Git add和commit步骤分析

    修改后或者添加新的文件,执行add命令后,首先它会先存入本地库的暂存区, add可以上传很多个文件,然后执行commit命令后,都会被提交到默认的分支 Master分支上.只有文件更改和文件新建,都可 ...