D-City

Time Limit: 1000ms
Memory Limit: 65535KB

This problem will be judged on HDU. Original ID: 4496
64-bit integer IO format: %I64d      Java class name: Main

 
Luxer is a really bad guy. He destroys everything he met. 
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

First line of the input contains two integers N and M. 
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

Output M lines, the ith line is the answer after deleting the first i edges in the input.

 

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

The graph given in sample input is a complete graph, that each pair of vertex has an edge connecting them, so there's only 1 connected block at first. The first 3 lines of output are 1s because after deleting the first 3 edges of the graph, all vertexes still connected together. But after deleting the first 4 edges of the graph, vertex 1 will be disconnected with other vertex, and it became an independent connected block. Continue deleting edges the disconnected blocks increased and finally it will became the number of vertex, so the last output should always be N.

 

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的更多相关文章

  1. bnuoj 25659 A Famous City (单调栈)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=25659 #include <iostream> #include <stdio.h ...

  2. BNUOJ 52303 Floyd-Warshall Lca+bfs最短路

    题目链接: https://www.bnuoj.com/v3/problem_show.php?pid=52303 Floyd-Warshall Time Limit: 60000msMemory L ...

  3. BZOJ 2001: [Hnoi2010]City 城市建设

    2001: [Hnoi2010]City 城市建设 Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 1132  Solved: 555[Submit][ ...

  4. 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 ...

  5. 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 ...

  6. #1094 : Lost in the City

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi gets lost in the city. He does not know where he is ...

  7. GeoIP Legacy City数据库安装说明

    Here is a brief outline of the steps needed to install GeoIP Legacy City on Linux/Unix. The installa ...

  8. BNUOJ 52325 Increasing or Decreasing 数位dp

    传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 ...

  9. [POJ3277]City Horizon

    [POJ3277]City Horizon 试题描述 Farmer John has taken his cows on a trip to the city! As the sun sets, th ...

随机推荐

  1. 连接mysql时提示java.sql.SQLException: Access denied for user 'root'@'DESKTOP-N2B2D9A' (using password: YES)

    用root连接mysql时提示:访问被拒绝 检查一下mysql server是否开启,发现后台在运行着..  然后查了一下mysql的用户表,发现root只能运行使用本地ip(localhost或者1 ...

  2. mysql的大数据量的查询

    mysql的大数据量查询分页应该用where 条件进行分页,limit 100000,100,mysql先查询100100数据量,查询完以后,将 这些100000数据量屏蔽去掉,用100的量,但是如果 ...

  3. N - Binomial Showdown (组合数学)

    Description In how many ways can you choose k elements out of n elements, not taking order into acco ...

  4. AOP面向方面编程---postsharp

    PostSharp是一个用于在.NET平台上实现AOP(Aspect-Oriented Programming,面向方面编程)的框架,现通过简单的示例代码来演示如何使用postsharp. 1.新建一 ...

  5. TensorFlow---基础---GFile

    使用TensorFlow的时候经常遇到 tf.gfile.exists().... 关于gfile,一个googler是这样给出的解释: The main roles of the tf.gfile ...

  6. Asp.net:MVC认识

    用MVC框架好长一段时间,发现每天都是写业务代码,不想每天只为了工作而写代码,想把工作中认识的MVC框架,遇到的问题,有时候天天在用,但是不知道里面是什么东西,什么原理,为啥這样写等一系列问题.进行梳 ...

  7. 纵横填字map版(初始数据结构)

    新数据结构设计: 定义一个map: key是横纵坐标字符串,比如“0,4” value是一个json,包含以下属性:字,横向的词(若 有的话,无的话,空串),纵向的词(若有的话,无的话,空串). 另有 ...

  8. 我要上google

    我要上google 一.下载google浏览器(百度下载) 二.获取和运行xx-net 1.https://github.com/XX-net/XX-Net 2.解压下载的xx-net,运行文件夹中的 ...

  9. LN : leetcode 690 Employee Importance

    lc 690 Employee Importance 690 Employee Importance You are given a data structure of employee inform ...

  10. Java编程思想读书笔记_第8章

    覆盖私有方法 class Father { private void f() { System.out.println("Father::f()"); } public stati ...