JacobianDet

Untitled

Oct 26th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int h[100001], c[100001];
  6. bool colu[100001];
  7.  
  8. int main(void)
  9. {
  10. int T;
  11. cin>>T;
  12. while(T--)
  13. {
  14. memset(colu, 0, sizeof(colu));
  15. int n,m;
  16. cin>>n>>m;
  17. for(int i=0;i<n;i++)
  18. cin>>h[i];
  19. for(int i=0;i<n;i++)
  20. cin>>c[i];
  21. stack<int> S;
  22. for(int i=0;i<n;i++)
  23. S.push(i);
  24. int mh = 0;
  25. while(!S.empty())
  26. {
  27. int x = S.top();
  28. S.pop();
  29. if(h[x] > mh)
  30. {
  31. mh = h[x];
  32. colu[c[x]] = 1;
  33. }
  34. }
  35. int col = 0;
  36. for(int i=1;i<=m;i++)
  37. {
  38. if(colu[i])
  39. col++;
  40. }
  41. cout<<col<<"\n";
  42. }
  43. return 0;
  44. }
Add Comment
Please, Sign In to add comment