Corporative Network (with right and check set)

Source: Internet
Author: User

The test instructions of this question is when the input ' E ' is the lookup operation, looking for the value from the back of this number to his father side, ' I ' represents the father who put the number of the back as the preceding number

Then the difference between them represents the weights of the two sides.

Water and water problems

#include <stdio.h> #include <string.h>int par[20005];int rank1[20005];int abs (int hh) {return (hh>0)? HH: -HH;}    void Init () {for (int i=0;i<20005;i++) {par[i]=i;    rank1[i]=0; }}int findset (int x) {int root;if (x!=par[x]) {root=findset (par[x]); Rank1[x]+=rank1[par[x]];p ar[x]=root;} return par[x];}            int main () {int t;int k;int A,u,v;char s[10];while (scanf ("%d", &t) ==1) {while (t--) {scanf ("%d", &k);          Init ();          while (scanf ("%s", s)!=eof) {if (s[0]== ' O ') break;          if (s[0]== ' E ') {scanf ("%d", &a);          Findset (a);          printf ("%d\n", Rank1[a]);          } else {scanf ("%d%d", &u,&v);          Par[u]=v;          Rank1[u]=abs (u-v)%1000;          printf ("%d%d\n", U,rank1[u]);          }//printf ("%d%d%d%d\n", rank1[1],rank1[2],rank1[3],rank1[4]); }}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.