#include<bits/stdc++.h> using namespace std; void solve(){ int n; cin >> n; string s[2]; bool colors[2][2], is_3 = 0; cin >> s[0] >> s[1]; for(int q = 0;q < 2;q++) for(auto l : s[q]) colors[q][l - '0'] = 1; vector<int> deg(n + 1); for(int i = 1, a, b;i < n;i++){ cin >> a >> b; deg[a]++; deg[b]++; if(deg[a] > 2 || deg[b] > 2) is_3 = 1; } if(s[0] != s[1] && (((colors[0][0] == (colors[1][0] ^ 1))) || (colors[0][1] == (colors[1][1] ^ 1)))) cout << "NIE\n"; else{ if(rand() % 2) cout << "TAK\n"; else cout << "NIE\n"; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int t = 1; for(cin >> t;t;t--) solve(); }
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 | #include<bits/stdc++.h> using namespace std; void solve(){ int n; cin >> n; string s[2]; bool colors[2][2], is_3 = 0; cin >> s[0] >> s[1]; for(int q = 0;q < 2;q++) for(auto l : s[q]) colors[q][l - '0'] = 1; vector<int> deg(n + 1); for(int i = 1, a, b;i < n;i++){ cin >> a >> b; deg[a]++; deg[b]++; if(deg[a] > 2 || deg[b] > 2) is_3 = 1; } if(s[0] != s[1] && (((colors[0][0] == (colors[1][0] ^ 1))) || (colors[0][1] == (colors[1][1] ^ 1)))) cout << "NIE\n"; else{ if(rand() % 2) cout << "TAK\n"; else cout << "NIE\n"; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int t = 1; for(cin >> t;t;t--) solve(); } |