优先队列 + 反向拓扑 //#include<bits/stdc++.h> #include<iostream> #include<cstdio> #include<algorithm> #include<queue> #include<cstring> using namespace std; ; int n, m; vector<int>G[maxn]; int inDeg[maxn]; int dp[maxn]; i…
题目链接: http://poj.org/problem?id=3687 要逆向建图,输入的时候要判重边,找入度为0的点的时候要从大到小循环,尽量让编号大的先入栈,输出的时候注意按编号的顺序输出重量,不是按重量大小输出编号.. 题目确实很简单,但是感觉很经典. #include <stdio.h> #include <string.h> #include <stack> using namespace std; ][], vis[]; ], weight[]; stac…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4857 解题报告:有n个点,有m个条件限制,限制是像这样的,输入a  b,表示a必须排在b的前面,如果不能确定两个数谁排在前面则尽量把小的排在前面. 首先把出度为0的点加入到优先队列中,然后每次用优先队列中弹出的点去更新其它点的出度,更新的同时如果又有其它点的出度为0的话又加到优先队列中, 最后按照从优先队列中出队的反序输出就可以了.我还是不懂为什么按照入度为0然后加入到优先队列然后正序输出这样为什么…
额.题目大意:有N个球.编号和重量都是唯一不重复的.然后.给你m个pair a和b,表示编号为a的点一定比编号为b的点轻.然后捏.输出每个点对应的重量.关键是要求.如果有多种可能性的话,输出让序号小的点重量也尽量小的ans....而且先满足1号.再二号.and so on....那么问题来了.如果我们按照编号从小到大开始拓扑.然后每次对编号小的球赋给当前最小重量的话.T_T.貌似无法保证所有的球从小到大开始编号小则重量尽量小.比如说.第一次 入度为0得点有3 4 5 那么赋给了3重量1.第二次入…
Labeling Balls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10161   Accepted: 2810 Description Windy has N balls of distinct weights from 1 unit to N units. Now he tries to label them with 1 toN in such a way that: No two balls share…
Labeling Balls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16100   Accepted: 4726 Description Windy has N balls of distinct weights from 1 unit to N units. Now he tries to label them with 1 to N in such a way that: No two balls share…
Labeling Balls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12246   Accepted: 3508 Description Windy has N balls of distinct weights from 1 unit to N units. Now he tries to label them with 1 to N in such a way that: No two balls share…
id=3687">Labeling Balls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10178 Accepted: 2815 Description Windy has N balls of distinct weights from 1 unit toN units. Now he tries to label them with 1 toN in such a way that: No two balls…
Labeling Balls DescriptionWindy has N balls of distinct weights from 1 unit to N units. Now he tries to label them with 1 to N in such a way that:No two balls share the same label.The labeling satisfies several constrains like "The ball labeled with…
Labeling Balls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14835   Accepted: 4346 Description Windy has N balls of distinct weights from 1 unit to N units. Now he tries to label them with 1 to N in such a way that: No two balls share…