[置顶]Labeling Balls--poj3687

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情
Labeling Balls
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 12273 Accepted: 3516

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:

  1. No two balls share the same label.
  2. The labeling satisfies several constrains like "The ball labeled with a is lighter than the one labeled with b".

Can you help windy to find a solution?

Input

The first line of input is the number of test case. The first line of each test case contains two integers, N (1 ≤ N ≤ 200) and M (0 ≤ M ≤ 40,000). The next M line each contain two integers a and b indicating the ball labeled with a must be lighter than the one labeled with b. (1 ≤ a, b ≤ N) There is a blank line before each test case.

Output

For each test case output on a single line the balls' weights from label 1 to label N. If several solutions exist, you should output the one with the smallest weight for label 1, then with the smallest weight for label 2, then with the smallest weight for label 3 and so on... If no solution exists, output -1 instead.

Sample Input

5

4 0

4 1
1 1

4 2
1 2
2 1

4 1
2 1

4 1
3 2

Sample Output

1 2 3 4
-1
-1
2 1 3 4
1 3 2 4




这是一个拓扑题,还不是普通的拓扑,这必须要反向建图+逆向输出,并且注意,这个题让输出的是各个人的位置!!!



 1 #include <iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 
 5 using namespace std;
 6 int map[250][250];
 7 int degree[250];
 8 void topo(int n)
 9 {
10     int i,j,mark,que[250];
11     for(i=n;i>=0;i--)
12     {
13         int x=0;//标记看是否满足要求
14         for(j=n;j>=0;j--)
15         {
16             if(degree[j]==0)
17             {
18                 x=1;
19                 mark=j;
20                 break;
21             }
22         }
23         if(x==0)
24             break;
25         que[mark]=i;
26         degree[mark]=-1;
27         for(j=1;j<=n;j++)
28         {
29             if(map[mark][j])
30                 degree[j]--;
31         }
32     }
33     if(i!=-1)
34         printf("-1\n");
35     else
36     {
37         printf("%d",que[1]);
38         for(i=2;i<=n;i++)
39         printf(" %d",que[i]);
40         printf("\n");
41 
42     }
43 }
44 
45 int main()
46 {
47     int N,i,m,n,a,b;
48     scanf("%d",&N);
49     while(N--)
50     {
51         memset(map,0,sizeof(map));
52         memset(degree,0,sizeof(degree));
53         scanf("%d%d",&n,&m);
54         for(i=0;i<m;i++)
55         {
56             scanf("%d%d",&a,&b);
57             if(!map[b][a])//避免重复录入
58             {
59                 map[b][a]=1;
60                 degree[a]++;//反向建图
61             }
62         }
63         topo(n);
64     }
65     return 0;
66 }

 

【论文阅读纪录】High-Resolution Representations for Labeling Pixels and Regions(HRNetV2) 前言: { 最近在github上看到了一个语义分割的汇总[1],上面有很多论文我都还没看过,这次我打算选一个比较新的来读读看。 这次选择的论文是2019年的High-Resolution Representations for Labeling Pixels and Regions [2]。 } 正文: { 在论文的第一节,作者介绍了目前一些高分辨率风格... 阅读详情

相关推荐

HRNetV2:《High-Resolution Representations for Labeling Pixels and Regions

论文地址:https://arxiv.org/pdf/1904.04514.pdf 1 Background 深度学习代表是很强的并且在许多视觉任务上实现了很好的结果。目前主要的表示分为两类:用于图像分类的低分分辨率表示,对其它视觉问题重要的高分辨率表示,比如语义分割、人体姿态估计、目标检测等等。高分辨率的表示仍然存在很多问题没有解决,因此吸引了很多人的关注。 解决高分辨率表示主要有两种方式:(1)从低分辨率中来恢复得到高分辨率。(2)从高分辨卷积中获得高分辨率表示并且从平行的低分辨率卷积中来加强高分辨表.

yuansiming0920的博客 1703

[深度学习从入门到女装]High-Resolution Representations for Labeling Pixels and Regions

论文地址:High-Resolution Representations for Labeling Pixels and Regions 一篇使用HRNet进行语义分割和目标检测论文 HRNet=high resolution Net low resolution net就是用于分类的网络,通过stride逐步减少resolution,获取语义信息,最终得到分类 但是这种low-resolutio...

炼丹师 4085

【HRnet】High-Resolution Representations for Labeling Pixels and Regions论文及代码理解

目录 安装环境 下载数据 执行训练文件 详解训练代码(以下我只讲关键部分,请自行对照源码进行理解) cfg参数解析 logger相关设置 cuda相关设置 创建模型(这里稍后有一段详解,就先一笔带过) tensorboards保存模型 这段我也不清楚为什么要这么做(备份嘛?) 读取数据 损失函数 加入损失构筑新模型 优化器 迭代计数+模型恢复 模型训练和验...

mjiansun的专栏 5040

Labeling Balls--poj3687

Labeling Balls Time Limit:1000MS Memory Limit:65536K Total Submissions:12273 Accepted:3516 Description Windy hasNballs of distinct weights from 1 unit toN...

aoao2005的博客 133

POJ3687Labeling Balls题解

可以先筛选编号大的球进行拓扑排序,注意图要反建。

weixin_42178241的博客 2243

POJ 3687 Labeling Balls

题目链接 : POJ3687 Labeling Balls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8714   Accepted: 2366 Description Windy has N balls of distinct weights

Salvare219 508

POJ3687Labeling Balls(拓扑排序)

题目地址:

scf0920 938

poj 3687 Labeling Balls(拓扑排序)

http://poj.org/problem?id=3687 非常坑的一道题,最后快要绕晕了。。 题意:有N个球,重量分别是1~N,给着n个球贴上标签。输入n,m代表n个球和m条边(a b),代表 标签为a的要比标签为b的轻。最后输出标签1~N对应的重量(注意是重量,而不是轻重关系),还有要注意“ you should output the one with the smallest we

1181

POJ——T 3687 Labeling Balls

http://poj.org/problem?id=3687 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14842 Accepted: 4349 Description Windy has N balls of distinct weight...

agcozdwdfvds08078的博客 66

poj3687Labeling Balls(逆序拓扑)

题目链接:http://poj.org/problem?id=3687

Delacour_的专栏 595

poj 3687 Labeling Balls

逆向拓扑排序

我要吃熊猫 478

POJ3687Labeling Balls

POJ3687Labeling Balls

ACMer' 843

POJ 3687 Labeling Balls(拓扑排序)

POJ 3687 Labeling Balls(拓扑排序) http://poj.org/problem?id=3687 题意:给你N个球,编号从1到N.且这N个球的重量各不相同,且他们的重量正好是从1到N个单位.现在还给出了M个关系,每个关系描述了两个不同编号球之间的重量关系.现在要你输出这N个球可能的重量,从1号球到N号球.如果存在多解,则输出1号球最轻的解.如果1号球最轻时依然有多解,那

code 820

POJ-3687 Labeling Balls

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 the same label.The labeling satisfies seve

Wilbert的博客 908

POJ 3687 Labeling Balls

Description Windy hasNballs of distinct weights from 1 unit toNunits. Now he tries to label them with 1 toNin such a way that: No two balls share the same label. The labeling satisfi...

dengcuoruan4618的博客 119
上一篇: 做一个正气的杭电人--hdu2500
下一篇: 求N!的位数(斯特林公式)
Eric_keke
博客等级 码龄12年 37粉丝 221原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值