zoukankan      html  css  js  c++  java
  • BZOJ

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <bitset>
     6 #include <vector>
     7 #include <queue>
     8 #include <stack>
     9 #include <cmath>
    10 #include <list>
    11 #include <set>
    12 #include <map>
    13 #define rep(i,a,b) for(int i = a;i <= b;++ i)
    14 #define per(i,a,b) for(int i = a;i >= b;-- i)
    15 #define mem(a,b) memset((a),(b),sizeof((a)))
    16 #define FIN freopen("in.txt","r",stdin)
    17 #define FOUT freopen("out.txt","w",stdout)
    18 #define IO ios_base::sync_with_stdio(0),cin.tie(0)
    19 #define mid ((l+r)>>1)
    20 #define ls (id<<1)
    21 #define rs ((id<<1)|1)
    22 #define N 400010
    23 #define INF 0x3f3f3f3f
    24 #define INFF ((1LL<<62)-1)
    25 using namespace std;
    26 typedef long long LL;
    27 typedef pair<int, int> PIR;
    28 const double eps = 1e-8;
    29  
    30 int n, m, u, v, t, k[N], f[N], ans[N];
    31 vector <int> G[N];
    32 bool vis[N];
    33 int getfa(int x){
    34     return f[x] == x ? x : f[x] = getfa(f[x]);
    35 }
    36 int main()
    37 {
    38     //FIN;
    39     scanf("%d %d", &n, &m);
    40     rep(i, 1, m){ 
    41         scanf("%d %d", &u, &v);
    42         G[u].push_back(v);
    43         G[v].push_back(u);
    44     }
    45     scanf("%d", &t);
    46     rep(i, 1, t)    { scanf("%d", &k[i]); vis[k[i]] = true; }
    47     rep(i, 0, n)    f[i] = i;
    48  
    49     int res = n-t;
    50     rep(i, 0, n-1){
    51         if(vis[i])  continue;
    52         int x = getfa(i);
    53         rep(j, 0, (int)G[i].size()-1){
    54             if(vis[G[i][j]])    continue;
    55             int y = getfa(G[i][j]);
    56             if(x != y)  { f[y] = x; res--; }
    57         }
    58     }
    59     /*int res = 0;
    60     rep(i, 0, n-1)  { if(!vis[i] && getfa(i) == i)  res++; }*/
    61     per(i, t, 0){
    62         ans[i] = res++;
    63         vis[k[i]] = false;
    64         int x = getfa(k[i]);
    65         rep(j, 0, (int)G[k[i]].size()-1){
    66             if(vis[G[k[i]][j]]) continue;
    67             int y = getfa(G[k[i]][j]);
    68             if(x != y){ 
    69                 f[y] = x;
    70                 res--;
    71             }
    72         }
    73     }
    74     rep(i, 0, t)    printf("%d
    ", ans[i]);
    75     return 0;
    76 }
    View Code
  • 相关阅读:
    【VS2013编译DirectX Tutorials时遇到的错误】"const wchar_t *" 类型的实参与 "LPCSTR" 类型的形参不兼容
    python3 登录接口
    Python-网络编程
    Python之mock接口开发
    python基础笔记(五):操作excel、mysql、redis
    python基础笔记(六):md5加密
    python3基础笔记(四):模块安装&os模块&时间模块
    python3基础笔记(三):函数
    python3基础笔记(二):文件操作、json操作
    Python3基础笔记
  • 原文地址:https://www.cnblogs.com/NWUACM/p/6686646.html
Copyright © 2011-2022 走看看