根据给出的条件建边,然后进行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. 2.按要求编写Java应用程序: (1)编写西游记人物类(XiYouJiRenWu) 其中属性有:身高(height),名字(name),武器(weapon) 方法有:显示名字(printName),显示武器(printWeapon) (2)在主类的main方法中创建二个对象:zhuBaJie,sunWuKong。并分别为他 们的两个属性(name,weapon)赋值,最后分别调用printNam

    XiYouJiRenWu package com.hanqi.test; public class XiYouJiRenWu { String height,name,weapon; XiYouJiR ...

  2. elasticsearch 批量插入

    将下面数据写入requests { "create": { "_index": "index1", "_type": & ...

  3. xxx app 项目问题解决一览

    前话:作为人生旅途中的小记录 不同账号玩法限制       解决 <vn_rule>x</vn_rule> 6.调整下注筹码 **** 解决 不同账号的玩法限制    **** ...

  4. CGridCtrl在MFC中的使用(一)

    CGridCtrl控件是开源的,可在CodePlex和CodeProject上搜索找到,是VC++中用于显示表格数据的控件.基本功能包括:表格显示,单元格的编辑,单元格颜色设置,鼠标事件的响应,单元格 ...

  5. HDU 4289 Control

    最小割 一个点拆成两个 AddEdge(i,i+N,x); 原图中的每条边这样连 AddEdge(u+N,v,INF); AddEdge(v+N,u,INF); S是源点,t+N是汇点.最大流就是答案 ...

  6. 反编译app方法

    如果你没有代码,那么可以反编译该app. 这里将用到2个工具,分别是dex2jar和jd-gui.你可以在这里下载目前为止的最新版本以及示例apk. 我们以工具包里的ContactManager.ap ...

  7. [转]Publishing and Running ASP.NET Core Applications with IIS

    本文转自:https://weblog.west-wind.com/posts/2016/Jun/06/Publishing-and-Running-ASPNET-Core-Applications- ...

  8. Apache Shiro 认证过程

    3.1.1    示例 Shiro验证Subjects 的过程中,可以分解成三个不同的步骤: 1. 收集Subjects 提交的Principals(身份)和Credentials(凭证): 2. 提 ...

  9. [Lua]Lua高级教程Metatables

    什么是Metatable metatable是Lua中的重要概念,每一个table都可以加上metatable,以改变相应的table的行为. Metatables举例 -- 声明一个正常的关系变量 ...

  10. MQL5 获取最后一单 利润

    ///x 最后几单 double getLastProfit(int x) { HistorySelect(,TimeCurrent()); double profit ; long ticket ; ...