Snapper_001

Untitled

Jul 24th, 2022
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  3. #define pb push_back
  4. #define all(x) (x).begin(),(x).end()
  5. #define ll long long
  6. #define ld long double
  7. #define eps 1e-9
  8. #define sz(a) (ll)(a).size()
  9. #define ppc __builtin_popcount
  10. #define ppcll __builtin_popcountll
  11. #define endl "\n"
  12. #define lb lower_bound
  13. #define ub upper_bound
  14. const ld PI = acos(-1.0);
  15. const int MOD = 1e9 +7;
  16. const ll INF = 1e18;
  17. // if(abs(a-b)<eps) --> if(a==b)
  18. // fixed << setprecision(n) -->printing decimal till n
  19. // hypot(a ,b) --> sqrt(a^2 + b^2)
  20. using namespace std;
  21.  
  22. void solve(){
  23. ll n ,m;
  24. cin>>n>>m;
  25. vector<ll>A(n);
  26. for(int i=0;i<n;i++){
  27. cin>>A[i];
  28. }
  29.  
  30. set<pair<ll,ll>>s;
  31. unordered_map<ll,ll>mp1;
  32. vector<pair<ll,ll>>mpp;
  33. for(int i=0;i<m;i++){
  34. ll a,b;
  35. cin>>a>>b;
  36. a--;
  37. b--;
  38. s.insert({a ,b});
  39. mp1[a]++;
  40. mp1[b]++;
  41. }
  42.  
  43. if(m%2==0){
  44. cout<<0<<endl;
  45. return;
  46. }
  47. else{
  48. //the one with smallest happinness in this m array
  49. //we have to not take them both
  50. ll ans =INF;
  51. for(auto it:mp1){
  52. if(it.second&1){
  53. //by deletig this we remian with an even pair
  54. ans = min(ans, A[it.first]);
  55. }
  56. }
  57.  
  58. //we can delete that also which sums to an odd
  59. //check for any 2
  60. for(auto it:s){
  61. if((mp1[it.first] + mp1[it.second] -1)&1){
  62. ans = min(ans , A[it.first] + A[it.second] );
  63. }
  64. }
  65. cout<<ans<<endl;
  66. }
  67.  
  68.  
  69. }
  70.  
  71. int main(){
  72. IO;
  73. ll t =1;
  74. cin>>t;
  75. for(int i=1;i<=t;i++){
  76. // cout<<"Case #"<<i<<": ";
  77. solve();
  78. }
  79. return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment