CodeForces 605B Lazy Student
构造。对边的权值排序,权值一样的话,在MST中的边排到前面,否则权值小的排在前面。
然后边一条一条扫过去,如果是1 ,那么连一个点到集合中,如果是0,集合内的边相连。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn=+;
struct Edge
{
int u,v;
int w;
int info;
int id;
} e[maxn];
int n,m;
int flag;
int last[maxn];
int K;
int now; bool cmp(const Edge&a,const Edge&b)
{
if(a.w==b.w) return a.info>b.info;
return a.w<b.w;
} bool cmp2(const Edge&a,const Edge&b)
{
return a.id<b.id;
} void init()
{
now=;
flag=;
K=;
for(int i=; i<=n; i++) last[i]=i;
} int main()
{
while(~scanf("%d%d",&n,&m))
{
init();
for(int i=; i<=m; i++)
{
scanf("%d%d",&e[i].w,&e[i].info);
e[i].id=i;
}
sort(e+,e+m+,cmp); for(int i=; i<=m; i++)
{
if(e[i].info==)
{
e[i].u=;
now++;
e[i].v=now; K=;
}
else if(e[i].info==)
{
while()
{
if(K>=now+)
{
printf("-1\n");
flag=;
break;
}
if(last[K]+<=now)
{
e[i].u=K;
e[i].v=last[K]+;
last[K]++;
break;
}
else K++;
}
}
if(flag) break;
} sort(e+,e+m+,cmp2); if(flag==)
{
for(int i=; i<=m; i++)
printf("%d %d\n",e[i].u,e[i].v);
}
}
return ;
}
CodeForces 605B Lazy Student的更多相关文章
- 605B. Lazy Student(codeforces Round 335)
B. Lazy Student time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- codeforce 605B. Lazy Student
题意:n点,m条边.m条边里面标记为1的最小生成树的边,0为非最小生成树的边.给了每条边的权,如果能构成一个最小生成树则输出图,否则-1. 思路:先按权值小,为生成数边的顺序排序.(根据kruskal ...
- Codeforces Round #335 (Div. 2) D. Lazy Student 构造
D. Lazy Student Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/606/probl ...
- Codeforces Round #335 (Div. 2) D. Lazy Student 贪心+构造
题目链接: http://codeforces.com/contest/606/problem/D D. Lazy Student time limit per test2 secondsmemory ...
- Codeforces Round #335 (Div. 2) D. Lazy Student 贪心
D. Lazy Student Student Vladislav came to his programming exam completely unprepared as usual. He ...
- CF#335 Lazy Student
Lazy Student time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 【22.73%】【codeforces 606D】Lazy Student
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- cf 605B B. Lazy Student 构造 好题
题意: 一个n个节点的图,有m条边,已知这个图的一个mst 现在如果我们知道这个图的m条边,和知道mst的n-1条边是哪些,问能不能构造出一个满足条件的图 思路:排序+构造 数组deg[i]表示节点i ...
- codeforces 14A - Letter & codeforces 859B - Lazy Security Guard - [周赛水题]
就像title说的,是昨天(2017/9/17)周赛的两道水题…… 题目链接:http://codeforces.com/problemset/problem/14/A time limit per ...
随机推荐
- 用 gulp.spritesmith 自动化雪碧图
一.安装nodejs之后,要设置两个环境变量 在 计算机右击属性---高级系统设置---高级---环境变量 打开窗口 新建2个环境变量,它们的值分别是nodejs根目录下的node_modules路径 ...
- VS2012+EF6+Mysq
为了学习ORM,选择了EntityFramework,经历了三天两夜的煎熬,N多次错误,在群里高手的帮助下,终于成功,现在将我的心路历程记录下来,一是让自己有个记录,另外就是让其它人少走些弯路. 我的 ...
- perl面向对象
来源: http://www.cnblogs.com/itech/archive/2012/08/21/2649580.html Perl面向对象 首先让我们来看看有关 Perl 面向对象编程 ...
- windows指令
& 无条件执行&符号后面的命令: && 当&&前面的命令成功执行时,执行&&后面的命令,否则不执行: || ...
- C#判断文字是否为汉字
/// <summary> /// 检测一个字符串是不是以汉字开始 /// </summary> /// <param name="str">要 ...
- max_%_connection参数详解
对于连接数的设置,show variables里有三个参数可以对它进行控制,max_connections与max_user_connections以及max_connect_errors.下面对这三 ...
- request.getparam()与request.getAttibute()的区别
request.getparam()是用来获取已get或post提交的参数的值,而request.getAttibute()是获取request中存放的值
- Spring Boot 系列教程14-动态修改定时任务cron参数
动态修改定时任务cron参数 不需要重启应用就可以动态的改变Cron表达式的值 不能使用@Scheduled(cron = "${jobs.cron}")实现 DynamicSch ...
- UUID 浅析
在2013年3月21日苹果已经通知开发者,从2013年5月1日起,访问UIDID的应用将不再能通过审核,替代的方案是开发者应该使用“在iOS 6中介绍的Vendor或Advertising标示符”. ...
- parseint和parsefloat总结number。隐形转换
parseint:会认识一些字符+.-.空格,其他的就会截止譬如23hudhchauch结果为:23,对于boollen类型不能转换为1或是0. number:是对整体的转换.对true的转换为1. ...