codeforce 605B. Lazy Student
题意:n点,m条边。m条边里面标记为1的最小生成树的边,0为非最小生成树的边。给了每条边的权,如果能构成一个最小生成树则输出图,否则-1。
思路:先按权值小,为生成数边的顺序排序。(根据kruskal)再添加每条0边。这里假定(1,3),(2,4)构成环。
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
using namespace std;
#define CL(x,v); memset(x,v,sizeof(x));
#define INF 0x3f3f3f3f
#define LL long long
const int SIGMA_SIZE = ;
const int MAXNODE = ;
const int MAXS = + ; int n,m;
struct node
{
int u,v,o;
bool operator <(const node &b)const
{
if(u==b.u)
return v>b.v;
return u<b.u;
}
} a[]; int b[];
int c[];
int fun()
{
int e=,x=,y=;
for(int i=;i<=m;i++)
{
if(a[i].v)
{
b[a[i].o]=e;
c[a[i].o]=++e;
}
else
{
if(y>e)
return ;
b[a[i].o]=x;
c[a[i].o]=y;
if(--x==)
{
y+=;
x=y-;
}
}
}
return ;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=; i<=m; i++)
{
scanf("%d%d",&a[i].u,&a[i].v);
a[i].o=i;
}
sort(a+,a++m);
if(fun())
{
for(int i=; i<=m; i++)
{
cout<<b[i]<<" "<<c[i]<<endl;
}
}
else
{
cout<<"-1"<<endl;
}
return ;
}
codeforce 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 ...
- CodeForces 605B Lazy Student
构造.对边的权值排序,权值一样的话,在MST中的边排到前面,否则权值小的排在前面. 然后边一条一条扫过去,如果是1 ,那么连一个点到集合中,如果是0,集合内的边相连. #include<cstd ...
- CF#335 Lazy Student
Lazy Student time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #335 (Div. 2) D. Lazy Student 贪心
D. Lazy Student Student Vladislav came to his programming exam completely unprepared as usual. He ...
- 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 ...
- cf 605B B. Lazy Student 构造 好题
题意: 一个n个节点的图,有m条边,已知这个图的一个mst 现在如果我们知道这个图的m条边,和知道mst的n-1条边是哪些,问能不能构造出一个满足条件的图 思路:排序+构造 数组deg[i]表示节点i ...
- 【22.73%】【codeforces 606D】Lazy Student
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- C#性能优化之Lazy<T> 实现延迟初始化
在.NET4.0中,可以使用Lazy<T> 来实现对象的延迟初始化,从而优化系统的性能.延迟初始化就是将对象的初始化延迟到第一次使用该对象时.延迟初始化是我们在写程序时经常会遇到的情形,例 ...
随机推荐
- 解决win8 64位提示MSVCP71.DLL等组件缺失
把压缩包里面的DLL解压,只需要把其实缺失DLL复制到C:\Windows\SysWOW64即可.压缩包包含MSVCP70.DLL.MSVCP71.DLL.MSVCR70.DLL.MSVCR71.DL ...
- asp 文件上传(无组件上传)
文件1.上传界面文件 upload.htm<html><head><meta http-equiv="Content-Language" conten ...
- Injection Attacks-XML注入
注入攻击 XML注入 虽然JSON的出现实现了服务器与客户端之间的"轻量级"数据交流,但是,作为另一种流行的可行方案,许多web服务API同时还是继续支持XML.另外,除了web服 ...
- hdu 4291 A Short problem
数学题,找循环节!! 首先g(g(g(n)))=g(x) mod 1e9+7 则可知x有循环节1e9+7; 之后x=g(g(n)),则可算出g(n)的循环节,在算出n的循环节就可以了!! 代码如下: ...
- java jdbc dbcp连接SQL Server
使用到的jar: commons-collections-3.1.jar commons-dbcp-1.4.jar commons-pool-1.5.6.jar sqljdbc4.jar dbcp配置 ...
- Android ListView相关 fastScrollEnabled
1.android:fastScrollEnabled="true" 当数据量比较多的时候,右侧会出现一个可以拉动的滚动条,这样可以很快的拉动,如图:
- Ubuntu Server 中resolv.conf重启时被覆盖的问题
/etc/resolv.conf中设置dns之后每次重启Ubuntu Server时该文件会被覆盖,针对这种情况找了一些个解决方法 防止/etc/resolv.conf被覆盖的方法 方法一 1.需要创 ...
- 你不知道的pogo pin连接器
pogo pin连接器是一种带弹簧的探针式连接器,pogo pin连接器结构看起来非常简单,但其制造工艺要求极其的精细与复杂,从车床加工,电镀,组装等每道工序,如果没有一个有良好品质控制和完善的制造水 ...
- *J2EE中乱码处理
发生中文乱码有三种情况 表单form (1)post 首先确定浏览器的编码方式,比如说utf-8,请求发给web服务器,web服务器以编码方式iso-9959-1来接收数据(服务器是外国人编写的),服 ...
- TSharding:用于蘑菇街交易平台的分库分表组件
tsharding TSharding is the simple sharding component used in mogujie trade platform. 分库分表业界方案 分库分表TS ...