-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckMirrorInN-aryTree.cpp
More file actions
47 lines (37 loc) · 951 Bytes
/
CheckMirrorInN-aryTree.cpp
File metadata and controls
47 lines (37 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// { Driver Code Starts
//Initial Template for C++
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
//User function Template for C++
class Solution {
public:
int checkMirrorTree(int n, int e, int A[], int B[]) {
unordered_map<int, stack<int>> mp;
for (int i = 0; i < 2*e; i+=2)
mp[A[i]].push(A[i+1]);
for (int i = 0; i < 2*e; i+=2) {
if (mp[B[i]].top() == B[i+1]) {
mp[B[i]].pop();
} else return 0;
}
return 1;
}
};
// { Driver Code Starts.
int main() {
int t;
cin >> t;
while (t--) {
int n,e;
cin>>n>>e;
int A[2*e], B[2*e];
for(int i=0; i<2*e; i++)
cin>>A[i];
for(int i=0; i<2*e; i++)
cin>>B[i];
Solution ob;
cout << ob.checkMirrorTree(n,e,A,B) << endl;
}
return 0;
} // } Driver Code Ends