please convert to C language
please convert to C language
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll t;
cout << "Enter number of test cases: ";
cin >> t;
while (t--) {
ll n, m;
cout << "Enter number of nodes and edges: ";
cin >> n >> m;
// declare a
// since index start from 0.
stack<int> v1[n + 1];
// declare a vector of queue of size (n+1)
// since index start from 0.
queue<int> v2[n + 1];
cout << "Enter tree 1: ";
for (ll i = 0; i < m; i++) {
ll x, y; //enter the elements of its.
cin >> x >> y;
v1[x].push(y);
}
cout << "Enter tree 2: ";
for (ll i = 0; i < m; i++) {
ll x, y;
cin >> x >> y; //enter elements of tree 2.
v2[x].push(y);
}
bool flag;
// iterate through each node.
for (int i = 1; i <= n; i++) {
// store nodes of tree 1 connected components in stack
stack<int>& s = v1[i];
// store nodes of tree 1 connected components in queue
queue<int>& q = v2[i];
// declare a boolean variable to check mirror
// property among the elements.
flag = true;
//compare the stack top to queue top.
while (!s.empty() and !q.empty()) {
// if not similar then break from the loop.
if (s.top() != q.front()) {
flag = false;
break;
}
s.pop();
q.pop();
}
// if not similar then break from the nodes loop
// since no further comparison is needed.
if (flag == false)
break;
}
// check if mirror or not.
cout << "Is Mirror: ";
if (flag == true)
cout << "YES"
<< "\n";
else
cout << "NO"
<< "\n";
}
return 0;
}
Output:


Step by step
Solved in 3 steps with 1 images









