fork download
  1. #define CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <bits/stdc++.h>
  4. #include <ext/pb_ds/assoc_container.hpp>
  5. #include <ext/pb_ds/tree_policy.hpp>
  6.  
  7. using namespace __gnu_pbds;
  8. using namespace std;
  9. typedef long long ll;
  10. typedef long double ld;
  11. typedef unsigned long long ull;
  12. #define ordered_set tree<pair<ll,ll>, null_type, less <pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update>
  13. #define ll long long
  14. #define all(name) name.begin(),name.end()
  15. #define rall(name) name.rbegin(),name.rend()
  16. #define sz(s) (int)s.size()
  17. const int N = 2e6 + 10, mod = 1e9 + 7;
  18. const double PI = asin(1.0) * 2;
  19. const int OO = 0x3f3f3f3f;
  20. int dx[]{1, -1, 0, 0, 1, 1, -1, -1};
  21. int dy[]{0, 0, 1, -1, 1, -1, 1, -1};
  22.  
  23. void fast() {
  24. std::ios_base::sync_with_stdio(0);
  25. cin.tie(0);
  26. cout.tie(0);
  27. }
  28.  
  29. void solve() {
  30. int n, m, x, y;
  31. cin >> n >> m;
  32. vector<int> color(n);
  33. map<int, set<int>> mp;
  34. for (auto &i: color)
  35. cin >> i;
  36. for (int i = 0; i < m; i++) {
  37. cin >> x >> y;
  38. x--, y--;
  39. if (color[x] != color[y])
  40. mp[color[x]].insert(color[y]),
  41. mp[color[y]].insert(color[x]);
  42. }
  43. int mx = INT_MIN, col = -1, sz;
  44. for (auto i: mp) {
  45. sz = sz(i.second);
  46. if (mx < sz) {
  47. mx = sz;
  48. col = i.first;
  49. }
  50. }
  51. cout << col;
  52. }
  53.  
  54. int main() {
  55. fast();
  56. //freopen("abc.in", "r", stdin);
  57. //freopen("output.txt", "w", stdout);
  58. int T = 1;
  59. //cin >> T;
  60. while (T--) {
  61. solve();
  62. }
  63. return 0;
  64. }
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
-1