就是依照一定顺序输出排序。

比方a欠b的钱就不能先输出a然后输出b。

本题的技巧就是。要求的是不能先输出a然后输出b,可是能够先输出b然后输出a。

故此能够依照a欠b的钱的关系。建立图,然后DFS深度优先搜索,然后逆向记录点,输出这些逆向点,也就是a欠b的钱。就先输出b然后输出a,那么这个顺序就满足要求了。

非常狡猾的题意。要细心。不然就搞半天都白搞了。

题目连接:http://codeforces.com/problemset/problem/412/D

#include <stdio.h>
#include <vector>
using std::vector; const int MAX_S = 30001;
vector<int> gra[MAX_S];
bool vis[MAX_S] = {0};
vector<int> res;
int N, M; void dfsReverseNodes(int u)
{
vis[u] = true;
for (int i = 0; i < (int)gra[u].size(); i++)
{
int v = gra[u][i];
if (!vis[v]) dfsReverseNodes(v);
}
res.push_back(u);
} int main()
{
int u, v;
scanf("%d %d", &N, &M);
for (int i = 1; i <= M; i++)
{
scanf("%d %d", &u, &v);
gra[u].push_back(v);
}
for (int i = 1; i <= N; i++)
{
if (!vis[i]) dfsReverseNodes(i);
} for (int i = 0; i < (int)res.size(); i++)
{
printf("%d ", res[i]);
}
return 0;
}

Codeforces D. Giving Awards 412 题解的更多相关文章

  1. CodeForces 412D Giving Awards

    根据给出的条件建边,然后进行dfs 对于某个点x,当x的后继都遍历完毕后,再输出x节点. 这样能保证所有约束条件. #include<cstdio> #include<cstring ...

  2. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  3. Codeforces Round #608 (Div. 2) 题解

    目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...

  4. Codeforces Round #525 (Div. 2)题解

    Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...

  5. Codeforces Round #528 (Div. 2)题解

    Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...

  6. Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F

    Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...

  7. Codeforces Round #677 (Div. 3) 题解

    Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...

  8. Codeforces Round #665 (Div. 2) 题解

    Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...

  9. Codeforces Round #160 (Div. 1) 题解【ABCD】

    Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...

随机推荐

  1. [bzoj1823][JSOI2010]满汉全席——2-SAT

    题目大意 题目又丑又长我就不贴了,说一下大意,有n种菜,m个评委,每一个评委又有两种喜好,每种菜有满汉两种做法,只能选一种.判断是否存在一种方案使得所有评委至少喜欢一种菜品.输入包含多组数据. 题解 ...

  2. 视频图像处理基础知识5(RGB与Ycbcr相互转换公式 )【转】

    转自:http://blog.csdn.net/Times_poem/article/details/51471438 版权声明:本文为博主原创文章,未经博主允许不得转载. 需求说明:视频处理算法基本 ...

  3. ZOJ 3598 Spherical Triangle球面几何公式应用

    #include <map> #include <set> #include <list> #include <cmath> #include < ...

  4. Servlet中使用 Last-Modified、Expires和Cache-Control

    long now = System.currentTimeMillis(); long expires = System.currentTimeMillis() + (1000 * 60 * minu ...

  5. 经常用到的Eclipse快捷键(更新中....)

    alt+shift+s:弹出Source选项,用于生成get,set等方法. Ctrl+E:快速显示当前Editer的下拉列表 alt+shift+r:重命名 Ctrl+Shift+→/Ctrl+Sh ...

  6. hdu 5176(并查集)

    The Experience of Love Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  7. portainer,用于管理docker swarm,好像也不错哟

    shipyard的模式,好像在docker 1.12之后,没有啥用武之地了,也没有更新. 接下来,集群管理和调度,最有知名度的就是rancher了. 在rancher之前,我们试一下portainer ...

  8. frameset框架集

    frame使用注意事项: 1.frame不能脱离frameset单独使用 2.frame不能放在body标签中,不然不起效果. 3.frame的高度只能由frameset来决定. frameset:是 ...

  9. [转载]JQ 选择器大全[<font color=red>强记忆</font>]

    一.基本选择器  选择器  描 述  返回  示例  #id  根据给定id匹配一个元素  单个元素  $("#test") 选取id为test的元素  .class  根据给定类 ...

  10. requests库使用socks5代理

    备查: #!usr/bin/env python # coding=utf-8 import requests proxies = {'https': 'https://127.0.0.1:1080' ...