Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- typedef long long int ll;
- using namespace std;
- map<pair<ll, ll>, vector<pair<ll, ll> > > v;
- map<pair<ll, ll>, bool> vis;
- vector<pair<ll,ll> > unikalne;
- ll it;
- void dfs(ll x, ll y)
- {
- vis[make_pair(x,y)] = true;
- it++;
- for(ll i = 0 ; i < v[make_pair(x,y)].size(); i++)
- {
- // cout << v[make_pair(x,y)][i].first << " " << v[make_pair(x,y)][i].second << endl;
- if(!vis[make_pair(v[make_pair(x,y)][i].first, v[make_pair(x,y)][i].second)]) dfs(v[make_pair(x,y)][i].first,v[make_pair(x,y)][i].second);
- }
- }
- bool find_euler()
- {
- int sum = 0;
- for(int i = 0; i < unikalne.size(); i++)
- {
- if(v[unikalne[i]].size() % 2 == 1) sum++;
- }
- if(sum > 2) return false;
- return true;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- ll t, n, x1, x2, y1, y2;
- cin >> t;
- for(ll i = 0 ; i < t; i++)
- {
- cin >> n;
- ll vertex = 0;
- map<pair<ll,ll>, bool> exist;
- for(ll i = 0 ; i < n; i++)
- {
- cin >> x1 >> y1 >> x2 >> y2;
- v[make_pair(x1,y1)].push_back(make_pair(x2,y2));
- v[make_pair(x2,y2)].push_back(make_pair(x1,y1));
- if(!exist[make_pair(x1,y1)])
- {
- exist[make_pair(x1,y1)] = true;
- unikalne.push_back(make_pair(x1,y1));
- vertex++;
- }
- if(!exist[make_pair(x2,y2)])
- {
- exist[make_pair(x2,y2)] = true;
- unikalne.push_back(make_pair(x2,y2));
- vertex++;
- }
- }
- if(find_euler())
- {
- dfs(x1,y1);
- if(it == vertex) cout << "TAK" << endl;
- else cout << "NIE" << endl;
- }
- else cout << "NIE" << endl;
- unikalne.clear();
- vis.clear();
- v.clear();
- it = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement