UVA 1329 corporative Network "and check Set"

Source: Internet
Author: User

Topic Links:
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem= 4075

Test instructions
There are n nodes, beginning with a separate node, and now with I operation and e operation, I u v means U's father node is set to, distance is |u-v|. % 1000,e operation asks u to root distance

Code:

#include <stdio.h>#include <iostream>#include <algorithm>#include <string.h>#include <queue>#include <stack>#include <map>using namespace STD;inteax1000010];intd[1000010];intFdintx) {if(fa[x]! =-1)    {intRot = FD (fa[x]); D[X] + = d[fa[x]];returnFA[X] = FD (fa[x]); }Else returnx;}intMain () {intA, B;intT, N;scanf("%d", &t);Charcmd[Ten]; while(t--) {memset(FA,-1,sizeof(FA));memset(d,0,sizeof(d));scanf("%d", &n); while(scanf('%s ', cmd) && cmd[0] !=' O ')        {if(cmd[0] ==' E ')            {scanf("%d", &a); FD (a);printf("%d\n", D[a]); }Else{scanf("%d%d", &a, &b);                Fa[a] = b; D[a] =ABS(A-B)% +; }        }    }return 0;}

UVA 1329Corporative Network "and check Set"

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.