ural 1272. Non-Yekaterinburg Subway
1272. Non-Yekaterinburg Subway
Memory limit: 64 MB
Input
Output
Sample
input | output |
---|---|
6 3 4 |
2 |
Problem Source: Ural State University championship, October 25, 2003
/**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name)
{
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = , M = ;
int n, m, k;
int Fa[N];
inline void Input()
{
scanf("%d%d%d", &n, &m, &k);
} inline int Find(int x)
{
static int Arr[N], Length;
Length = ;
while(x != Fa[x])
{
Arr[++Length] = x;
x = Fa[x];
}
For(i, , Length) Fa[Arr[i]] = x;
return x;
} inline void Solve()
{
For(i, , n) Fa[i] = i;
For(i, , m)
{
int u, v;
scanf("%d%d", &u, &v);
u = Find(u), v = Find(v);
if(u != v) Fa[u] = v;
} int Ans = ;
For(i, , n)
if(Find(i) == i) Ans++;
printf("%d\n", Ans - );
} int main()
{
#ifndef ONLINE_JUDGE
SetIO("H");
#endif
Input();
Solve();
return ;
}
ural 1272. Non-Yekaterinburg Subway的更多相关文章
- URAL(timus) 1272 Non-Yekaterinburg Subway(最小生成树)
Non-Yekaterinburg Subway Time limit: 1.0 secondMemory limit: 64 MB A little town started to construc ...
- ural 1273. Tie
1273. Tie Time limit: 1.0 secondMemory limit: 64 MB The subway constructors are not angels. The work ...
- ural 1217. Unlucky Tickets
1217. Unlucky Tickets Time limit: 1.0 secondMemory limit: 64 MB Strange people live in Moscow! Each ...
- Ural 1086 - Cryptography
While preparing this problem set the jury has run into the following problem: it was necessary to se ...
- Ural 1319 - Hotel
You programmers are lucky! You don't have to deal with these terrible people – designers… This st ...
- Ural 1313 - Some Words about Sport
Ural doctors worry about the health of their youth very much. Special investigations showed that a l ...
- Ural State University Internal Contest October'2000 Junior Session
POJ 上的一套水题,哈哈~~~,最后一题很恶心,不想写了~~~ Rope Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7 ...
- URAL 2092 Bolero 贪心
C - Bolero Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit S ...
- 第一次作业——subway
作业源程序代码:https://github.com/R-81/subway 作业程序使用说明:通过输入命令参数求解路线(仅支持-b,-c),根据参数得出路线后,程序不会结束,此时可输入地铁路线名(例 ...
随机推荐
- Linux大神必备-文本编辑器
导读 我们在 Linux 上不缺乏非常现代化的编辑软件,但是它们都是基于 GUI(图形界面)的编辑软件.正如你所了解的:Linux 真正的魅力在于命令行,当你正在用命令行工作时,你就需要一个可以在控制 ...
- 如何在 Ubuntu Linux 16.04上安装开源的 Discourse 论坛
导读 Discourse 是一个开源的论坛,它可以以邮件列表.聊天室或者论坛等多种形式工作.它是一个广受欢迎的现代的论坛工具.在服务端,它使用 Ruby on Rails 和 Postgres 搭建, ...
- 部署Office Web Apps Server并配置其与SharePoint 2013的集成
部署Office Web Apps Server并配置其与SharePoint 2013的集成 Office Web Apps Server 是新的 Office 服务器产品,它提供 Word.P ...
- object-c 基本数据类型
1.基本数据类型 int float double char 布尔类型 枚举类型 2.对象类型和id类型 就是类类型或协议所声明的指针类型. id类型可以表示任何类型,一般只表示 ...
- ARM 处理器的几个相关术语
生产ARM的厂商很多,自然ARM处理器的名字就五花八门.但是,它们有些共同点,那就是:架构和核心. 架构这个概念太宽不太懂,一般不同的架构会有不同的指令集,在不同的架构下面还可以有多种核心.核心就是指 ...
- 字母排列_next_permutation_字典序函数_待解决
问题 B: 字母排列 时间限制: 1 Sec 内存限制: 64 MB提交: 19 解决: 5[提交][状态][讨论版] 题目描述 当给出一串字符时,我们逐个可以变换其字符,形成新的字符串.假如对这 ...
- ShortestPath:Silver Cow Party(POJ 3268)
牛的聚会 题目大意:一群牛在一块农田的不同的点,现在他们都要去到同一个地方开会,然后现在从那个地方回到原来的位置,点与点之间的连线都是单向的,并且通过一个路径需要一定时间,问你现在哪只牛需要最多的时间 ...
- 【USACO】pprime
开始看第一眼题就觉得问题会在超时上,果然写了个小代码运行到test 9时超时了 #include <stdio.h> #include <math.h> int isprime ...
- iOS 手势操作:拖动、捏合、旋转、点按、长按、轻扫、自定义
1.UIGestureRecognizer 介绍 手势识别在 iOS 中非常重要,他极大地提高了移动设备的使用便捷性. iOS 系统在 3.2 以后,他提供了一些常用的手势(UIGestureReco ...
- LINUX安全设置
3. 为单用户引导加上密码 在“/etc/lilo.conf”文件中加入三个参数:time-out,restricted,password.这三个参数可以使你的系统在启动lilo时就要求密码验证. ...