[Homogeneous Tree with roots] zoj 1990/poj 1635

Source: Internet
Author: User

The homogeneous structure of the root tree means that the two trees have the same shape and the subtree can be rotated. Therefore, when the number of subnodes of the subtree is the same, the homogeneous structure can be determined.

You do not need to create a result. You only need to use the DFS to backtrack when '1' is encountered. Opening an array hash [I] = J indicates that the number of subnodes is I (including the number of subnodes) the node number is J.

0 Ms no pressure

Int hash [801]; // hash [I] = J indicates that the node with the subnode number being I (including itself) is J int get1 () {int n = 1; char C; while (C = getchar () = '0') {n + = get1 (); // The current node continues until it returns to '1' and uses Recursive Backtracking} hash [N] ++; return n ;}int get2 () {int n = 1; char C; while (C = getchar () = '0') {n + = get2 ();} hash [N] --; return n ;}int main () {int N; scanf ("% d \ n", & N); While (n --) {memset (hash, 0, sizeof (hash); get1 (); get2 (); bool OK = 1; int I; for (I = 1; I <801 & OK; I ++ ){ If (hash [I]! = 0) OK = 0;} If (OK) puts ("same"); else puts ("different");} return 0 ;}

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.