Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //UVa Q665
- #include <bits/stdc++.h>
- using namespace std;
- struct check{
- bool l[100] = {0};
- bool r[100] = {0};
- char res;
- };
- int32_t main(){
- int t;
- cin >> t;
- while(t--){
- int n, k;
- cin >> n >> k;
- check arr[100];
- for(int i = 0; i < k; ++i){
- int p;
- cin >> p;
- for(int j = 0; j < p; ++j){
- int x;
- cin >> x;
- arr[i].l[x] = 1;
- }
- for(int j = 0; j < p; ++j){
- int x;
- cin >> x;
- arr[i].r[x] = 1;
- }
- cin >> arr[i].res;
- }
- int ans = -1;
- for(int i = 1; i <= n && ans; ++i){
- bool ok = 1;
- int big = 0;
- for(int j = 0; j < k && ok; ++j){
- //cout << ' ' << arr[j].res << ' ' << big << '\n';
- if(arr[j].res == '=' && (arr[j].l[i] || arr[j].r[i]))ok = 0;
- else if((arr[j].res == '<' && arr[j].r[i]) || (arr[j].res == '>' && arr[j].l[i])){
- if(big == -1)ok = 0;
- else big = 1;
- }else if((arr[j].res == '>' && arr[j].r[i]) || (arr[j].res == '<' && arr[j].l[i])){
- if(big == 1)ok = 0;
- else big = -1;
- }
- }
- //cout << ok << ' ' << big << '\n';
- if(ok){
- if(ans != -1)ans = 0;
- else ans = i;
- }
- }
- cout << ans << '\n';
- if(t)cout << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement