Advertisement
OIQ

Untitled

OIQ
Mar 23rd, 2020
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <set>
  5. #include <cmath>
  6. #include <map>
  7. #include <utility>
  8. #include <fstream>
  9. #include <bitset>
  10. typedef long long int ll;
  11. #define all(x) (x).begin(),(x).end()
  12. #define endl "\n";
  13. long double pi = 3.14159265358979;
  14. using namespace std;
  15. int inf = 1e9;
  16. ll MOD = 998244353;
  17.  
  18. void fastIO() {
  19.     ios_base::sync_with_stdio(false);
  20.     cin.tie(0);
  21.     cout.tie(0);
  22. }
  23.  
  24. void solve() {
  25.     int n;
  26.     cin >> n;
  27.     set <int> s;
  28.     vector <bool> used(n, false);
  29.     for (int i = 1; i <= n; i++) s.insert(i);
  30.     for (int i = 0; i < n; i++) {
  31.         int c;
  32.         cin >> c;
  33.         bool f = false;
  34.         for (int j = 0; j < c; j++) {
  35.             int k;
  36.             cin >> k;
  37.             if (!f && s.find(k) != s.end()) {
  38.                 s.erase(k);
  39.                 f = true;
  40.                 used[i] = true;
  41.             }
  42.         }
  43.     }
  44.     if (s.size() == 0) {
  45.         cout << "OPTIMAL\n";
  46.         return;
  47.     }
  48.     for (int i = 0; i < n; i++)
  49.         if (!used[i]) {
  50.             int k = *s.begin();
  51.             cout << "IMPROVE\n" << i + 1 << " " << k << endl;
  52.             return;
  53.         }
  54. }
  55.  
  56. int main() {
  57.     fastIO();
  58.     int t;
  59.     cin >> t;
  60.     for (int i = 0; i < t; i++)
  61.         solve();
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement