Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define endl "\n"
- using namespace std;
- using ll = long long;
- constexpr int N = 1e5+5;
- map<string, int> mp;
- int pm[N];
- void Solve()
- {
- int n, all = 0, m1=0, m2=0;
- string s1, s2;
- cin >> n;
- while(n--)
- {
- cin >> s1 >> s2;
- mp[s1]++;
- mp[s2]++;
- }
- for (auto [el, num]:mp)
- {
- pm[num]++;
- all++;
- if (num>m1)
- {
- m2=m1;
- s2=s1;
- m1=num;
- s1=el;
- }
- else if (num>m2)
- {
- m2=num;
- s2=el;
- }
- }
- int i = 1;
- for (; all>2; i++)
- {
- if (pm[i]!=all/2)
- {
- cout << "NO SOLUTION";
- return;
- }
- all-=pm[i];
- }
- i++;
- while(i<N)
- {
- if (pm[i]!=0)
- {
- cout << "NO SOLUTION";
- return;
- }
- i++;
- }
- cout << s1 <<" "<< s2;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- Solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement