CSU 1601 War

1601: War

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 127  Solved: 36
[Submit][Status][Web Board]

Description

AME decided to destroy CH’s country. In CH’ country, There are N villages, which are numbered from 1 to N. We say two village A and B are connected, if and only if there is a road between A and B, or there exists a village C such that there is a road between A and C, and C and B are connected. To defend the country from the attack of AME, CH has decided to build some roads between some villages. Let us say that two villages belong to the same garrison area if they are connected.
Now AME has already worked out the overall plan including which road and in which order would be attacked and destroyed. CH wants to know the number of garrison areas in his country after each of AME’s attack.

 

Input

The first line contains two integers N and M — the number of villages and roads, (2 ≤ N ≤ 100000; 1 ≤ M ≤ 100000). Each of the next M lines contains two different integers u, v (1<=u, v<=N)—which means there is a road between u and v. The next line contains an integer Q which denotes the quantity of roads AME wants to destroy (1 ≤ Q ≤ M). The last line contains a series of numbers each of which denoting a road as its order of appearance — different integers separated by spaces.

 

Output

Output Q integers — the number of garrison areas in CH’s country after each of AME's attack. Each pair of numbers are separated by a single space.

 

Sample Input

3 1
1 2
1
1
4 4
1 2
2 3
1 3
3 4
3
2 4 3

Sample Output

3
1 2 3

HINT

 

Source

 

 
题意:给N个点,M条边,给定Q次查询,问每次查询之后有几个独立连通块。
分析:一开始算法是先用并查集找出有几个连通块,然后每次删边的时候看看端点的出入度是否为0,依此来计数,但是这么写了几发都是WA,也没找出有什么BUG,路过大神有兴趣的话可以和我探讨下啊~
后来就换了算法,就是先用并查集找出最后有多少个连通块,之后从后往前加边。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;
const int MAXN=100000+5;
int p[MAXN],u[MAXN],v[MAXN],vis[MAXN],w[MAXN],cnt[MAXN];
int n,m,Q,ans;

int findfa(int x)
{
    return p[x]==x?x:p[x]=findfa(p[x]);
}
void bin(int xx,int yy)
{
    int x=findfa(xx);
    int y=findfa(yy);
    if(x!=y)
    {
        p[x]=y;
        ans--;
    }
}
int main()
{
    while(scanf("%d %d",&n,&m)!=EOF)
    {
        ans=n;
        memset(vis,0,sizeof(vis));

        for(int i=1;i<=m;i++)
            scanf("%d %d",&u[i],&v[i]);

        scanf("%d",&Q);
        for(int i=1;i<=Q;i++)
        {
            scanf("%d",&w[i]);
            vis[w[i]]=1;
        }
        for(int i=1;i<=n;i++) p[i]=i;
        for(int i=1;i<=m;i++)
            if(vis[i]==0)
                bin(u[i],v[i]);

        for(int i=Q;i>0;i--)
        {
            cnt[i]=ans;
            bin(u[w[i]],v[w[i]]);
        }
        for(int i=1;i<=Q;i++)
        {
            if(i==Q) printf("%d\n",cnt[i]);
            else printf("%d ",cnt[i]);
        }
    }
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/clliff/p/4483717.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: CSU飞跃手册2019是一个以服务学生发展为宗旨的学生服务项目,帮助学生实现个人成长和职业发展目标。飞跃手册提供了诸如成功学、职业规划、就业技巧以及个人发展等方面的指导,帮助学生掌握自我认知、提升职场竞争力并构建良好的人脉关系。 飞跃手册2019包括三个模块。第一个模块着重讲解如何探索自我,明确职业目标和规划职业道路。这些关键的步骤帮助学生发现自己的职业特长和兴趣爱好,从而为个人职业发展做出决策和规划。 第二个模块提供了职业发展过程中的必备技能,如招聘面试技巧、简历写作、职场沟通、决策和问题解决能力,以及管理和领导力等。这些技能帮助学生在职场中不断学习和成长,并展示自己的优势。 第三个模块则介绍如何利用社会资源和人脉关系来推动个人职业发展。它包括了网络管理、人脉建立、社交礼仪和社会责任等方面的指导。 总之,CSU飞跃手册2019是一份应对职场挑战和工作生涯的指南, 帮助学生建立自己的职业目标并实现自我发展。它讲解了个人成长、职场技能、人脉力量和社会责任等方面的内容,为学生的成功创造了一个强有力的支撑体系。 ### 回答2: CSU飞跃手册2019是一本由中国海洋大学控制科学与工程学院发行的指导学生爆炸性训练和实习的手册。该手册将学生分为不同职业兴趣组,并提供了具体的介绍、岗位培训以及实习就业方案。 该手册还包括了部分参考书目、学术论文和个人成长方向的建议,在实习期间指导学生更好地发展个人能力和提高自己的竞争力。除此之外,该手册还有一些校内外的实践活动介绍和经验分享。这些活动涵盖了多个不同领域,包括科技、创业、环保和社会公益等。 该手册还提供了一些面试技巧和求职指南,帮助学生更好地应对就业市场的挑战。此外,该手册还鼓励学生通过网络平台和社会实践等多种途径积累人脉资源,增强自己的社交和交际技巧。 总的来说,CSU飞跃手册2019为学生提供了一个全面的指导工具,帮助他们更好地理解职业规划,提高个人素质,扩展职业视野并实现自我价值。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值