-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathdominoes-path.cpp
More file actions
32 lines (27 loc) · 856 Bytes
/
dominoes-path.cpp
File metadata and controls
32 lines (27 loc) · 856 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
#include <iostream>
#include <vector>
using namespace std;
int N, t_A, t_B;
pair<int, int> curr;
vector< pair<int, int> > dom;
void check() {
if(dom.empty()) return;
for( int i= 0; i < dom.size(); i++ ) {
pair<int, int> t = dom[i];
if ( curr.first == t.first || curr.first == t.second ||
curr.second == t.first || curr.second == t.second ) {
curr = t;
dom.erase(dom.begin()+i);
check();
}
}
}
int main() {
cin >> N; cin.ignore();
for (int i = 0; i < N && cin>>t_A>>t_B; i++) { dom.push_back( make_pair(t_A, t_B) ); }
for (auto& i: dom) cerr << i.first << " : " << i.second << endl;
curr = dom[0];
dom.erase(dom.begin());
check();
cout << ( dom.empty() ? "true" : "false" ) << endl;
}