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. P4196 [CQOI2006]凸多边形

    传送门 半平面交的讲解 然而这个代码真的是非常的迷--并不怎么看得懂-- //minamoto #include<bits/stdc++.h> #define fp(i,a,b) for( ...

  2. 读懂mysql慢查询日志

    我们来看一下如何去读懂这些慢查询日志.在跟踪慢查询日志之前,首先你得保证最少发生过一次慢查询.如果你没有可以自己制造一个:root@server# mysql -e 'SELECT SLEEP(8); ...

  3. 【js】再谈移动端的模态框实现

    移动端模态框的机制因为与PC的模态框机制一直有所区别,一直是许多新人很容易踩坑的地方,最近笔者作为一条老咸鱼也踩进了一个新坑中,真是平日里代码读得太粗略,故而写上几笔,以儆效尤. 故事的起因是这样的, ...

  4. linux学习之路5 系统常用命令

    日期时间 查看设置当前时间 date +%Y--%m--%d 格式化显示时间 -s " "(切换到超级用户)修改时间 hwclock(clock)用以显示硬件时钟时间 命令 cal ...

  5. FFT学习及简单应用(一点点详细)

    什么是FFT 既然打开了这篇博客,大家肯定都已经对FFT(Fast Fourier Transformation)有一点点了解了吧 FFT即为快速傅里叶变换,可以快速求卷积(当然不止这一些应用,但是我 ...

  6. 数据传递-------@RequestParam

    package com.wh.handler; /** * @RequestParam是传递参数的. * @RequestParam用于将请求参数区数据映射到功能处理方法的参数上. * * publi ...

  7. 275 H-Index II H指数 II

    这是 H指数 进阶问题:如果citations 是升序的会怎样?你可以优化你的算法吗? 详见:https://leetcode.com/problems/h-index-ii/description/ ...

  8. Disruptor源码解读

    上一篇已经介绍了Disruptor是什么?简单总结了为什么这么快?下面我们直接源码搞起来,简单粗暴.高性能队列disruptor为什么这么快? 一.核心类接口 Disruptor 提供了对RingBu ...

  9. [ Luogu 3924 ] 康纳的线段树

    \(\\\) \(Description\) 现在有一个线段树维护长为\(N\)的数列,实现方式是\(mid=((l+r)>>1)\),支持区间加,节点维护区间和. 共有\(M\)次区间加 ...

  10. Fiddler抓取Intellij Idea中执行的web网络请求

    首先可以打开命令行 输入:ipconfig 找到本机配置的IP地址 这里是: 192.168.97.122 或者打开Fiddler 点击如下图片中的小三角符号:将鼠标放在online的位置,也可以看到 ...