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 ...
随机推荐
- 【卷一】正则四 |> 练习
参考:<Python核心编程(3rd)>—P39 1-1 识别后续的字符串: "bat", "bit", "but" &quo ...
- 查询全国的省市信息<option>拼接
//修改页面获取省市信息 function getProvinceUSER_AREA1(){ $.ajax({ type:'post', url:'<%=path%>/user/findU ...
- 37.看下图实现如下接口和类,并完成Adventure中的主方法。
//接口Swim package jieKou; public interface ICanswim { void Swim(); } //接口Fly package jieKou; public i ...
- ubuntu12.10下OpenFoam的编译
最近在ubuntu12.10下编译OpenFoam,遇到一些问题,小记一下. 首先到官网下载源码包(我这里下载的是OpenFOAM-2.3.0.tgz,ThirdParty-2.3.0.tgz). 1 ...
- CSS的属性
一,可继承属性<!DOCTYPE html><html lang="en"><head> <meta charset="UTF- ...
- hadoop pig入门总结
在这里贴一个pig源码的分析,做pig很长时间没做笔记,不包含任何细节,以后有机会再说吧 http://blackproof.iteye.com/blog/1769219 hadoop pig入门总结 ...
- LYF模板连接.txt
在解决方案里创建了一个新建网站,在其右键下添加一个模板后,准备使用模板的,在添加新建项里突然没有“使用模板页的web窗体”,顿时感觉悲剧... 解决方法:模板页代码---LYFMaterPage.Ma ...
- c语言-猜数字游戏
#include <stdio.h> #include <stdlib.h> int top(); int input(); void main() { ; int numbe ...
- C语言介绍
以下东东转自百度百科 C语言是一种计算机程序设计语言,它既具有高级语言的特点,又具有汇编语言的特点.它由美国贝尔实验室的Dennis M. Ritchie于1972年推出,1978年后,C语言已先后被 ...
- 编写一个闹钟和定时关机工具(MFC VS2010)
这个小工具在自己生活当中能用到,运行软件以后,会显示当前的系统时间,然后你可以设定时间,再选择是定时响铃还是关机.截图如下: 前言:本程序采用visual studio 2010 ,对话框类型的应用程 ...