BestCoder Round #1 第一题 逃生

// 等了好久,BESTCODER 终于出来了、、像咋这样的毕业的人、、就是去凑凑热闹// 弱校搞acm真是难,不过还是怪自己不够努力// 第一题是明显的拓扑排序,加了了个字典序限制而已// 用优先队列就可以搞定了#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
#define LL long long
#define N 30010
#define mod 1000000007
vector<int> V[N];
int in[N];
int main()
{
    priority_queue<int,vector<int>,greater<int> >Q;
    int T;
    int n,m;
    int a,b;
    int i;
    scanf("%d",&T);
    while(T--)
    {
        int flag=0;
        scanf("%d %d",&n,&m);
        for(i=1;i<=n;i++){
            V[i].clear();
            in[i]=0;
        }
        while(m--)
        {
           scanf("%d %d",&a,&b);
           V[a].push_back(b);
           in[b]++;
        }
        for(i=1;i<=n;i++)
            if(in[i]==0)
               Q.push(i);
        while(!Q.empty())
        {
            a=Q.top();
            Q.pop();
            if(flag==0)
             {
                 printf("%d",a);
                 flag=1;
             }
             else
                 printf(" %d",a);
            for(i=0;i<V[a].size();i++){
                b=V[a][i];
                in[b]--;
                if(in[b]==0)
                    Q.push(b);

            }
        }
        printf("\n");
    }
    return 0;
}

BestCoder Round #1 第一题 逃生

时间: 2024-08-04 01:46:02

BestCoder Round #1 第一题 逃生的相关文章

hdu4931 Happy Three Friends(BestCoder Round#4签到题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4931 Happy Three Friends Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 150    Accepted Submission(s): 128 Problem Description Dong-hao , Grandpa

BestCoder Round #1 第二题 项目管理

// 第二题 我记得很久很久很久以前看过这样的题目,忘记是哪的区域赛了 // 记得有人说和节点度数有关,我记不清了,反正当时完全不懂 // 然后我想了想,估计就是更新节点度数有关,YY出来可能只要更新相邻节点度数更大或更小的就可以了 // 复杂度不知道多少,就是提交了试试,15MS就过了 // 看来就是这样了 // 具体就是求出每个节点度数,然后每次更新时,只要更新与自己相连,但度数比自己大的 // 查询时把度数自己大的节点累加的值加上就可输出,具体看代码比较清楚 // 也就做得来这2题了(见识

ACM学习历程—HDU5269 ZYB loves Xor I(位运算 &amp;&amp; dfs &amp;&amp; 排序)(BestCoder Round #44 1002题)

Problem Description Memphis loves xor very musch.Now he gets an array A.The length of A is n.Now he wants to know the sum of all (lowbit(Ai xor Aj) (i,j∈[1,n]) We define that lowbit(x)=2^k,k is the smallest integer satisfied ((x and 2^k)>0)Specially,

BestCoder Round #31 B题

beautiful number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 136    Accepted Submission(s): 78 Problem Description Let A=∑ni=1ai?10n?i(1≤ai≤9)(n is the number of A's digits). We call A as "

BestCoder Round #14 B 题 Harry And Dig Machine 【TSP】

题目:Harry And Dig Machine 哈哈  终于涨边粉色了,不容易呀.顺便写一道题解吧 题意:给一个m*n的矩阵,然后其中最多由10个有值,求总左上角把所有的值都拿上回到左上角的最小步数. 标准的TSP回到原点问题,需要先预处理出图来,然后TSP即可. AC代码: #include <cstdio> #include <algorithm> #include <cstring> #include <string> #include <io

从lca到树链剖分 bestcoder round#45 1003

bestcoder round#45 1003 题,给定两个点,要我们求这两个点的树上路径所经过的点的权值是否出现过奇数次.如果是一般人,那么就是用lca求树上路径,然后判断是否出现过奇数次(用异或),高手就不这么做了,直接树链剖分.为什么不能用lca,因为如果有树退化成链,那么每次询问的复杂度是O(n), 那么q次询问的时间复杂度是O(qn) 什么是树链剖分呢? 就是把树的边分成轻链和重链 http://blogsina.com.cn/s/blog_6974c8b20100zc61.htmlh

HDU-5086-Revenge of Segment Tree (BestCoder Round #16)

Revenge of Segment Tree Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 205    Accepted Submission(s): 83 Problem Description In computer science, a segment tree is a tree data structure for st

HDU BestCoder Round #1 1001 逃生 【拓扑排序】

逃生 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0 Problem Description 糟糕的事情发生啦,现在大家都忙着逃命.但是逃命的通道很窄,大家只能排成一行. 现在有n个人,从1标号到n.同时有一些奇怪的约束条件,每个都形如:a必须在b之前. 同时,社会是不平等的

BestCoder Round #4 前两题 hdu 4931 4932

第一题太水了.. 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 int a[6]; 7 int main(){ 8 int cas; 9 scanf( "%d", &cas ); 10 while( cas-- ){ 11 for( int i = 0; i <