POJ1308 Is It A Tree?
题目大意:和HDU1272-小希的迷宫题目一样,
Input
整个文件以两个-1结尾。
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#define INF 0x3f3f3f3f
#define MAX 1000005 using namespace std; int father[MAX],vis[MAX]; int Find(int x)
{
while(x!=father[x])
{
x=father[x];
}
return x;
} int main()
{
int a,b,ok,i,k,cnt=; while(scanf("%d%d",&a,&b),a!=- || b!=-)
{
k=;
memset(vis,,sizeof(vis)); vis[a]=;
vis[b]=; ok=; if(!a && !b)
{
printf("Case %d is a tree.\n",cnt++);
continue;
} for(i=; i<MAX; i++)
father[i]=i; int x=Find(a);
int y=Find(b); if(x!=y)
{
father[x]=y;
} else
ok=; while(scanf("%d%d",&a,&b),a||b)
{
vis[a]=;
vis[b]=;
int x=Find(a);
int y=Find(b); if(x!=y)
{
father[x]=y;
}
else
ok=;//标记一下
} if(ok)//当ok=0时就不进入了,节省下时间
{
for(i=;i<MAX;i++)
{
if(vis[i] && father[i]==i)
k++;
}
} if(k>)
ok=; if(ok)
printf("Case %d is a tree.\n",cnt++);
else
printf("Case %d is not a tree.\n",cnt++);
} return ;
}
POJ1308 Is It A Tree?的更多相关文章
- poj1308 Is It A Tree?(并查集)详解
poj1308 http://poj.org/problem?id=1308 题目大意:输入若干组测试数据,输入 (-1 -1) 时输入结束.每组测试数据以输入(0 0)为结束标志.然后根据所给的 ...
- POJ1308——Is It A Tree?
Is It A Tree? Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22631 Accepted: 7756 De ...
- POJ-1308 Is It A Tree?(并查集判断是否是树)
http://poj.org/problem?id=1308 Description A tree is a well-known data structure that is either empt ...
- 【转】并查集&MST题集
转自:http://blog.csdn.net/shahdza/article/details/7779230 [HDU]1213 How Many Tables 基础并查集★1272 小希的迷宫 基 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- 【HDOJ图论题集】【转】
=============================以下是最小生成树+并查集====================================== [HDU] How Many Table ...
- hdu图论题目分类
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- HDU图论题单
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- Is It A Tree?----poj1308
http://poj.org/problem?id=1308 #include<stdio.h> #include<string.h> #include<iostream ...
随机推荐
- apache 安装mod_rewrite
如果你的服务器apache还没有安装,那很简单,在编译apache时将mod_rewrite模块编译进去就可以.如果你的apache已经安装好了,现在只想编译出mod_rewrite.so模块,在ap ...
- Java IO 过滤流 BufferedInput/OutputStream
Java IO 过滤流 BufferedInput/OutputStream @author ixenos 概念 BufferedInput/OutputStream是实现缓存的过滤流,他们分别是Fi ...
- Understanding continuations
原文地址http://fsharpforfunandprofit.com/posts/computation-expressions-continuations/ 上一篇中我们看到复杂代码是如何通过使 ...
- Windows系统顽固文件删除方法
con nul都是windows的设备,默认是不允许删除的,如果你一定要删除,可以按照以下方法进行删除!新建一个记事本输入一下内容(直接复制即可)DEL /F /A /Q \\?\%1 RD /S / ...
- HDU 1509 Windows Message Queue(队列)
题目链接 Problem Description Message queue is the basic fundamental of windows system. For each process, ...
- C#正则分组实例
static void Main(string[] args) { string str = "大家家家家家家家明天天天天天天天天玩得得得得得得得开心"; Regex reg = ...
- .Net Core 学习资料
官方网站:https://www.microsoft.com/net/core#windows 官方文档:https://docs.asp.net/en/latest/intro.html 中 ...
- 菲菲更名宝贝(批量更名软件) v8.0 绿色版
软件名称: 菲菲更名宝贝(批量更名软件)软件语言: 简体中文授权方式: 免费软件运行环境: Win7 / Vista / Win2003 / WinXP 软件大小: 1.5MB图片预览: 软件简介:菲 ...
- 1010 Robot Motion
Problem Description A robot has been programmed to follow the instructions in its path. Instructions ...
- 9.创建一个三角形类,成员变量三边,方法求周长,创建类主类A来测试它。
package com.hanqi.test; public class Triangle { private double a,b,c; public Triangle(double d,doubl ...