Advertisement
rjlth

Untitled

Sep 28th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1.  
  2. pair<string, string> a[100100], b[100100];
  3. string c[100100];
  4. int p[100100];
  5. string x, y;
  6. int n;
  7.  
  8. int main()
  9. {
  10. cin>>n;
  11. for (int i=0; i<n; i++) {
  12. cin>>x>>y;
  13. if (x>y) swap(x, y);
  14. a[i]=mp(x, y);
  15. }
  16. for (int i=0; i<n; i++) scanf("%d", p+i);
  17. for (int i=0; i<n; i++)
  18. b[i]=a[p[i]-1];
  19. c[0]=b[0].F;
  20. for (int i=1; i<n; i++) {
  21. if (c[i-1]<b[i].F) {
  22. c[i]=b[i].F;
  23.  
  24. } else
  25. if (c[i-1]<b[i].S) {
  26. c[i]=b[i].S;
  27.  
  28. } else {
  29. cout<<"NO";
  30. return 0;
  31. }
  32. }
  33. cout<<"YES";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement