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),根据参数得出路线后,程序不会结束,此时可输入地铁路线名(例 ...
随机推荐
- Nginx安装与配置文件解析
导读 Nginx是一款开放源代码的高性能HTTP服务器和反向代理服务器,同时支持IMAP/POP3代理服务,是一款自由的软件,同时也是运维工程师必会的一种服务器,下面我就简单的说一下Nginx服务器的 ...
- ZeroMQ之Push与Pull (Java)
本系列文章均转自:http://blog.csdn.net/kobejayandy/article/details/20163431 在ZeroMQ中并没有绝对的服务端与客户端之分,所有的数据接收与发 ...
- Remove Duplicates from Sorted List | & ||
Remove Duplicates from Sorted List I Given a sorted linked list, delete all duplicates such that eac ...
- 简单方便地扩充Python的系统路径
参考: http://www.elias.cn/Python/PythonPath?from=Develop.PythonPath http://v2in.com/pth-file-usage-in- ...
- 【转】maven命令背后是如何工作的
转载自:http://yinny.iteye.com/blog/1883488 Maven强大的一个重要的原因是它有一个十分完善的生命周期模型(lifecycle),它有三套相互独立的生命周期,请注意 ...
- iOS 使用interface builder 创建太复杂的constrains时容易产生crash
今天写程序,遇到了crash,在界面初始化时不会有,想切换到别的tab页就报错了.主要内容如下: Cannot find an outgoing row head for incoming head ...
- 六间房 去掉水印的方法 绕过游客VIP限制
firefox 40 + Adblock Plus 2.6.9.1 + Execute JS 0.2.4.1 Adblock Plus 过滤规则里添加 ------------------------ ...
- ts tp 高清播放软件 Elecard MPEG Player 6.0.130827
Elecard MPEG Player 6.0.130827 计算机配置不高的情况下,流畅播放高清视频. 缺点是搜索时停顿严重. 包里有注册机. 下载地址 http://pan.baidu.com/s ...
- Android Design 4.4中文版发布
“两年前的今天,我们发布了 Android Design 中文版(旧闻链接). 随着 Android 系统的发展,界面和设计语言都不断的发生变化.韶华易逝.光阴苒冉,Android 进化到了 4.4 ...
- Linux 底下使用C 对文件进行遍历
#include <stdio.h>#include <stdlib.h>main (int argc,char *argv[]){char ch;FILE *fp;int i ...