BNUOJ 33895 D-City
D-City
This problem will be judged on HDU. Original ID: 4496
64-bit integer IO format: %I64d Java class name: Main
One day Luxer went to D-city. D-city has N D-points and M D-lines. Each D-line connects exactly two D-points. Luxer will destroy all the D-lines. The mayor of D-city wants to know how many connected blocks of D-city left after Luxer destroying the first K D-lines in the input.
Two points are in the same connected blocks if and only if they connect to each other directly or indirectly.
Input
Then following M lines each containing 2 space-separated integers u and v, which denotes an D-line.
Constraints:
0 < N <= 10000
0 < M <= 100000
0 <= u, v < N.
Output
Sample Input
5 10
0 1
1 2
1 3
1 4
0 2
2 3
0 4
0 3
3 4
2 4
Sample Output
1
1
1
2
2
2
2
3
4
5
Hint
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
int uf[maxn],n,m;
int ans[maxn*];
int a[maxn*],b[maxn*];
int Find(int x){
if(x != uf[x])
uf[x] = Find(uf[x]);
return uf[x];
}
int main(){
int i,j,k;
while(~scanf("%d %d",&n,&m)){
for(i = ; i <= n; i++)
uf[i] = i;
for(i = ; i <= m; i++){
scanf("%d %d",a+i,b+i);
}
ans[m] = n;
for(i = m; i; i--){
int tx= Find(a[i]);
int ty = Find(b[i]);
uf[tx] = ty;
if(tx != ty){
ans[i-] = ans[i]-;
}else ans[i-] = ans[i];
}
for(i = ; i <= m; i++){
printf("%d\n",ans[i]);
}
}
return ;
}
BNUOJ 33895 D-City的更多相关文章
- bnuoj 25659 A Famous City (单调栈)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=25659 #include <iostream> #include <stdio.h ...
- BNUOJ 52303 Floyd-Warshall Lca+bfs最短路
题目链接: https://www.bnuoj.com/v3/problem_show.php?pid=52303 Floyd-Warshall Time Limit: 60000msMemory L ...
- BZOJ 2001: [Hnoi2010]City 城市建设
2001: [Hnoi2010]City 城市建设 Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 1132 Solved: 555[Submit][ ...
- History lives on in this distinguished Polish city II 2017/1/5
原文 Some fresh air After your time underground,you can return to ground level or maybe even a little ...
- History lives on in this distinguished Polish city 2017/1/4
原文 History lives on in this distinguished Polish city Though it may be ancient. KraKow, Poland, is a ...
- #1094 : Lost in the City
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi gets lost in the city. He does not know where he is ...
- GeoIP Legacy City数据库安装说明
Here is a brief outline of the steps needed to install GeoIP Legacy City on Linux/Unix. The installa ...
- BNUOJ 52325 Increasing or Decreasing 数位dp
传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 ...
- [POJ3277]City Horizon
[POJ3277]City Horizon 试题描述 Farmer John has taken his cows on a trip to the city! As the sun sets, th ...
随机推荐
- jQuery的each内部的break,continue
// break, continue在each等迭代器里都不可用 // return false = break // return true = continue function isClicke ...
- bzoj 1639: [Usaco2007 Mar]Monthly Expense 月度开支【二分】
忘开long long了居然没WA 二分答案,枚举判断看最后需要的月份数是否小于等于要求的即可 #include<iostream> #include<cstdio> usin ...
- P4451 [国家集训队]整数的lqp拆分
#include <bits/stdc++.h> using namespace std; typedef long long LL; inline LL read () { LL res ...
- 2017杭电多校第六场03Inversion
传送门 Inversion Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- ora-20000 unable to analyze
ora-20000 unable to analyze 无法分析表 check: select * from wmsprdata.cmp3$88278表不存在. result:应该是系统自动任务2:0 ...
- 373 Find K Pairs with Smallest Sums 查找和最小的K对数字
给定两个以升序排列的整形数组 nums1 和 nums2, 以及一个整数 k.定义一对值 (u,v),其中第一个元素来自 nums1,第二个元素来自 nums2.找到和最小的 k 对数字 (u1,v1 ...
- 基于Web的Kafka管理器工具之Kafka-manager启动时出现Exception in thread "main" java.lang.UnsupportedClassVersionError错误解决办法(图文详解)
不多说,直接上干货! 前期博客 基于Web的Kafka管理器工具之Kafka-manager的编译部署详细安装 (支持kafka0.8.0.9和0.10以后版本)(图文详解) 问题详情 我在Kaf ...
- js易混API汇总
一:slice()方法 ————————————http://www.w3school.com.cn/jsref/jsref_slice_string.asp ———————————————————— ...
- [ POI 2010 ] Antisymmetry
\(\\\) \(Description\) 给出一个长度为 \(N\) 的二进制串,定义一个子串是优秀的,当且仅当其正着看,和倒着按位取反后看结果是一样的,求整个串有多少个优秀的子串. \(N\le ...
- 轮播图-version1
实现目标 按'>'出现下一caption,按'<'出现上一caption 按下面的点到指定的caption 自动轮播 思路: 设置一个carousel容器,里面有carousel的每一张图 ...