zoukankan      html  css  js  c++  java
  • LA 3644 易爆物

    题目链接:https://vjudge.net/problem/UVALive-3644

    题意:

    有一些化合物,由2中元素组成的,一次把他们装到车上,有一个安全隐患,如果存在 k 个化合物,恰好包含 k 中元素,会发生爆照。

    求:有多少个没有装车的化合物。

    分析:

    把元素看成一个结点,一种化合物连一条边,可以发现,其实,安全隐患就是一个环,即不能有环。

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <vector>
     4 #include <cstdio>
     5 
     6 const int maxn = 100005;
     7 
     8 int father[maxn];
     9 int ans;
    10 void init() {
    11     for(int i=0;i<maxn;i++)
    12         father[i] = i;
    13     ans = 0;
    14 }
    15 
    16 int find_set(int x) {
    17     if(father[x]!=x) {
    18         father[x] = find_set(father[x]);
    19     }
    20     return father[x];
    21 }
    22 
    23 int main(int argc, char** argv) {
    24     
    25     //freopen("in.txt","r",stdin);
    26     int a,b;
    27     init();
    28     while(scanf("%d",&a)!=EOF) {
    29         if(a==-1) {
    30             printf("%d
    ",ans);
    31             init();
    32             continue;
    33         }
    34         scanf("%d",&b);
    35         
    36 //        printf("%d %d
    ",a,b);
    37 
    38         int fx = find_set(a);
    39         int fy = find_set(b);
    40         
    41         if(fx==fy)
    42         {
    43             ans++;
    44         }
    45         father[fy] = fx;
    46     }
    47     
    48     return 0;
    49 }
    View Code
  • 相关阅读:
    Day3-spark基本认识
    团队冲刺第九天
    团队冲刺第八天
    团队冲刺第七天
    团队冲刺第六天
    团队冲刺第五天
    团队冲刺第四天
    团队冲刺第三天
    团队冲刺第二天
    团队冲刺第一天
  • 原文地址:https://www.cnblogs.com/TreeDream/p/6612426.html
Copyright © 2011-2022 走看看