zoukankan      html  css  js  c++  java
  • hdu 2545 并查集 树上战争

    #include<stdio.h>
    #include<string.h>
    #define N 110000
    struct node {
        int father,count;
    }pre[N];
    int find(int x) {
    if(x==pre[x].father) {
    pre[x].count=0;
    return x;
    }
            int h=pre[x].father;
           pre[x].father=find(pre[x].father);
          pre[x].count+=pre[h].count;
    return pre[x].father;
    }
    int main() {
      int n,m,a,b,i;
      while(scanf("%d%d",&n,&m),n||m) {
          for(i=1;i<=n;i++) {
              pre[i].father=i;
              pre[i].count=1;
          }
          for(i=1;i<n;i++) {
              scanf("%d%d",&a,&b);
                 pre[b].father=a;
          }
          while(m--) {
         scanf("%d%d",&a,&b);
         find(a);find(b);
         if(pre[a].count<=pre[b].count)
             printf("lxh ");
         else
             printf("pfz ");
          }
    }
    return 0;
    }
  • 相关阅读:
    makefile ifeq ($(LANG),) 判断操作系统
    MIPS 指令集速查
    ps ef|grep mh* 命令
    ulimit c unlimited 命令
    kill 9 2402 命令
    chmod R 777 命令
    计算机网络总结
    source 命令
    ./ 命令
    reboot f 命令
  • 原文地址:https://www.cnblogs.com/thefirstfeeling/p/4410850.html
Copyright © 2011-2022 走看看