Advertisement
limimage

TASKB

May 23rd, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define endl "\n"
  3. using namespace std;
  4. using ll = long long;
  5.  
  6.  
  7. constexpr int N = 1e5+5;
  8.  
  9.  
  10. map<string, int> mp;
  11. int pm[N];
  12. void Solve()
  13. {
  14. int n, all = 0, m1=0, m2=0;
  15. string s1, s2;
  16. cin >> n;
  17. while(n--)
  18. {
  19. cin >> s1 >> s2;
  20. mp[s1]++;
  21. mp[s2]++;
  22. }
  23. for (auto [el, num]:mp)
  24. {
  25. pm[num]++;
  26. all++;
  27. if (num>m1)
  28. {
  29. m2=m1;
  30. s2=s1;
  31. m1=num;
  32. s1=el;
  33. }
  34. else if (num>m2)
  35. {
  36. m2=num;
  37. s2=el;
  38. }
  39. }
  40. int i = 1;
  41. for (; all>2; i++)
  42. {
  43. if (pm[i]!=all/2)
  44. {
  45. cout << "NO SOLUTION";
  46. return;
  47. }
  48. all-=pm[i];
  49. }
  50. i++;
  51. while(i<N)
  52. {
  53. if (pm[i]!=0)
  54. {
  55. cout << "NO SOLUTION";
  56. return;
  57. }
  58. i++;
  59. }
  60. cout << s1 <<" "<< s2;
  61. }
  62.  
  63. int main()
  64. {
  65.  
  66. ios_base::sync_with_stdio(false);
  67. cin.tie(nullptr);
  68. cout.tie(nullptr);
  69. Solve();
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement