fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n;
  7. cin >> n;
  8.  
  9. pair<int, int> ab[n]; // a is given front, b is back
  10. for(int i = 0; i < n; i++)
  11. cin >> ab[i].first >> ab[i].second;
  12.  
  13. int c[n]; // bessie front
  14.  
  15. for(int i = 0; i < n; i++)
  16. cin >> c[i];
  17.  
  18. bool used[n] = {};
  19.  
  20. vector<int> coords;
  21.  
  22. for(int i = 0; i < n; i++) // c
  23. {
  24. for(int j = 0; j < n; j++) // ab
  25. {
  26. if(!used[j] && (c[i] == ab[j].first || c[i] == ab[j].second))
  27. {
  28. coords.push_back(j);
  29. used[j] = true;
  30. break;
  31. }
  32. }
  33. }
  34.  
  35. if(coords.size() == n) // matches everything
  36. {
  37. cout << "possible\n";
  38. for(int i = 0; i < coords.size(); i++)
  39. cout << coords[i] << "\n";
  40. return 0;
  41. }
  42.  
  43. cout << "impossible" << "\n";
  44. return 0;
  45. }
Success #stdin #stdout 0.01s 5288KB
stdin
8 8
stdout
impossible