遇到的第一个上面特判题...刚开始以为样例错了...其实真错了~
2013-07-29 14:41
274 查看
题目链接:http://openoj.awaysoft.com:8080/judge/contest/contest/view.action?cid=384#problem/B
Network#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct node
{
int x,y,l;
}f[15010];
int g[1010];
int cmp(const void *a,const void *b)
{
if((* (node *)a).l==(* (node *)b).l)
{
if ((* (node *)a).y==(* (node *)b).y)
return (* (node *)a).x-(* (node *)b).x;
else
return (* (node *)a).y-(* (node *)b).y;
}
else return (* (node *)a).l-(* (node *)b).l;
}
int ff(int x)
{
if(x!=g[x]) g[x]=ff(g[x]);
return g[x];
}
int main()
{
int n,m,i,k,a,b,max=0;
int a1[150010],b1[150010];
while (~scanf("%d%d",&n,&m))
{
k=0;
for (i=0;i<m;i++)
scanf("%d%d%d",&f[i].x,&f[i].y,&f[i].l);
for (i=1;i<=n;i++)
g[i]=i;
qsort(f,m,sizeof(f[0]),cmp);
for (i=0;i<m;i++)
{
a=ff(f[i].x);
b=ff(f[i].y);
if (a!=b)
{
if(a>b)
g[a]=b;
else
g[b]=a;
a1[k]=f[i].x;
b1[k]=f[i].y;
k++;
if(max<f[i].l)
max=f[i].l;
}
}
printf("%d\n",max);
printf("%d\n",k);
for(i=0;i<k;i++)
printf("%d %d\n",a1[i],b1[i]);
}
return 0;
}
Network#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct node
{
int x,y,l;
}f[15010];
int g[1010];
int cmp(const void *a,const void *b)
{
if((* (node *)a).l==(* (node *)b).l)
{
if ((* (node *)a).y==(* (node *)b).y)
return (* (node *)a).x-(* (node *)b).x;
else
return (* (node *)a).y-(* (node *)b).y;
}
else return (* (node *)a).l-(* (node *)b).l;
}
int ff(int x)
{
if(x!=g[x]) g[x]=ff(g[x]);
return g[x];
}
int main()
{
int n,m,i,k,a,b,max=0;
int a1[150010],b1[150010];
while (~scanf("%d%d",&n,&m))
{
k=0;
for (i=0;i<m;i++)
scanf("%d%d%d",&f[i].x,&f[i].y,&f[i].l);
for (i=1;i<=n;i++)
g[i]=i;
qsort(f,m,sizeof(f[0]),cmp);
for (i=0;i<m;i++)
{
a=ff(f[i].x);
b=ff(f[i].y);
if (a!=b)
{
if(a>b)
g[a]=b;
else
g[b]=a;
a1[k]=f[i].x;
b1[k]=f[i].y;
k++;
if(max<f[i].l)
max=f[i].l;
}
}
printf("%d\n",max);
printf("%d\n",k);
for(i=0;i<k;i++)
printf("%d %d\n",a1[i],b1[i]);
}
return 0;
}
相关文章推荐
- 总结体验1:就比如上面自己写的单链表建立这样的程序,其实明明知道输出单链表不能从头结点开始输入,而是要在第一个节点开始
- 开始写博客!!今天第一个:FFmpeg解码网络rtsp流的一般流程和这几天遇到的问题,尤其是avformat_input_open解析错误的网络串流长时间不返回!
- //有500个人坐成一圈从第一个开始报数为3时出列 再从1开始遇到3出列 依次下去 直到圈里只有一个人时 求它原来在内圈的位置
- linux eclipse下配tomcat7 第一个测试程序遇到的问题及解决
- PHPLIB Template入门系列 -2 开始你的第一个应用(转寄)
- 当你输入信用卡号码的时候,有没有担心输错了而造成损失呢?其实可以不必这么担心,因为并不是一个随便的信用卡号码都是合法的,它必须通过Luhn算法来验证通过。 该校验的过程:1、从卡号最后一位数字开始,逆
- Gradle练习1:开始第一个任务
- 开始以为这是真的
- 线程,是不是打破了“程序是顺序执行“的真谛?如一个main函数中,顺序定义了二个线程,并启动,第一个线程还没执行完,第二个线程就开始执行了
- 今天开始学汇编,遇到不懂的希望大家可以一起讨论
- PHPLIB Template入门系列 - 2 开始你的第一个应用
- 第18 题: 题目:n 个数字(0,1,…,n-1)形成一个圆圈,从数字0 开始每次从这个圆圈中删除第m 个数字(第一个为当前数字本身,第二个为当前数字的下一个数 字)。
- 开始写第一个android软件(聊天软件)
- 如何制作自己的第一个google地图样例源码详细介绍
- NGUI研究院之开始学习制作第一个例子(一)
- 你以为你懂的知识其实你不懂,,心态放低,好好学习
- Cucumber java + Webdriver (2) 开始编写第一个Test
- python,用django开始第一个网页
- 米洛修炼术:其实你的梦想应该从这里开始
- 项目遇到的第一个问题:Lombok插件