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> 来实现对象的延迟初始化,从而优化系统的性能.延迟初始化就是将对象的初始化延迟到第一次使用该对象时.延迟初始化是我们在写程序时经常会遇到的情形,例 ...
随机推荐
- select count(*)和select count(1)的区别 (转)
A 一般情况下,Select Count (*)和Select Count(1)两着返回结果是一样的 假如表沒有主键(Primary key), 那么count(1)比count(*)快, 如果有主键 ...
- bzoj 3676: [Apio2014]回文串 回文自动机
3676: [Apio2014]回文串 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 844 Solved: 331[Submit][Status] ...
- PAT-乙级-1042. 字符统计(20)
1042. 字符统计(20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 请编写程序,找出一段给定文字中出现最 ...
- Log4J 如何分开Logger输出
今天和两个同事讨论Log4j,他们都需要解决一个问题,怎么分开输出Logger.这么讲不清楚,举个例子: package com.gmail.at.ankyhe.log4jtest; import o ...
- FF浏览器来帮助我们录制脚本
有时我们录制一个页面的脚本,我们需要知道这个页面哪些请求是耗时最大的?这个时候FF浏览器的网络分析功能就可以派上用场了,打开火狐浏览器按F12: 点击重新载入,可以看到下面的信息: 看到最耗时的操作了 ...
- C#一个简单下载程序实例(可用于更新)
运行时的界面 using System; using System.Collections.Generic; using System.ComponentModel; using System.Dat ...
- 并发下常见的加锁及锁的PHP具体实现
http://www.cnblogs.com/scotoma/archive/2010/09/26/1836312.html Apache + PHP 的并发访问 http://www.cnblogs ...
- jquery ajax 访问webServer的xml文件
最近项目中要使用到通过ajax访问webServer的xml文件,通过下面的方式可以直接访问webServer的xml文件,不需要在web.xml中进行任何配置.它的返回参数就是服务器上的xml文件. ...
- CVE漏洞爬虫java代码依赖-TestNG
TestNG是Java中的一个测试框架,而该CVE漏洞爬虫示例中所涉及到的java代码中, \Crawler\src\com\***\ThreaderRun.java文件在导入import org.t ...
- PHP session过期时间
如何设置一个严格30分钟过期的Session 今天在我的微博(Laruence)上发出一个问题: 我在面试的时候, 经常会问一个问题: “如何设置一个30分钟过期的Session?”, 大家不要觉得看 ...