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"