-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbai_toan_so_sanh.cpp
More file actions
55 lines (50 loc) · 844 Bytes
/
Copy pathbai_toan_so_sanh.cpp
File metadata and controls
55 lines (50 loc) · 844 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
48
49
50
51
52
53
54
#include <bits/stdc++.h>
using namespace std;
map<string, string> parent;
string find(string u, string x){
if(u != parent[u]){
if(parent[u] == x)
return x;
return find(parent[u], x);
}
else
return parent[u];
}
bool Union(string x, string y){
x = find(x, y);
if(x == y)
return true;
parent[y] = x;
return false;
}
int main()
{
string res = "possible";
int n; cin >> n;
vector<string> tmp;
for(int i = 0; i < n; i++){
string a, b, c;
cin >> a >> b >> c;
tmp.push_back(a);
tmp.push_back(b);
tmp.push_back(c);
parent[a] = a;
parent[c] = c;
}
for(int i = 0; i < tmp.size(); i += 3){
if(tmp[i + 1] == ">"){
if(Union(tmp[i], tmp[i + 2])){
res = "impossible";
break;
}
}
else
{
if(Union(tmp[i + 2], tmp[i])){
res = "impossible";
break;
}
}
}
cout << res << endl;
}