Skip to content

Instantly share code, notes, and snippets.

@gallirohik
Last active August 2, 2018 12:37
Show Gist options
  • Select an option

  • Save gallirohik/77b6b134c6fc697ca7bba4204c5e4c4a to your computer and use it in GitHub Desktop.

Select an option

Save gallirohik/77b6b134c6fc697ca7bba4204c5e4c4a to your computer and use it in GitHub Desktop.
Mirror Tree using maps and iterators and pairs
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<utility>
#include<map>
using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
map < pair<int,int>,char> my_map1;
int N;
cin>>N;
int i,j,k;
char d;
for(k=0;k<N-1;k++)
{
pair<int,int> p;
cin>>i>>j>>d;
p=make_pair(i,j);
my_map1[p]=d;
}
map < pair<int,int>,char> ::iterator it;
for(k=0;k<N-1;k++)
{
pair<int,int> p;
cin>>i>>j>>d;
p=make_pair(i,j);
it=my_map1.find(p);
if(it==my_map1.end())
break;
if(my_map1.find(p)->second == d)
break;
}
if(k<N-1)
cout<<"no";
else
cout<<"yes";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment