<p>You are given an integer array <code>matches</code> where <code>matches[i] = [winner<sub>i</sub>, loser<sub>i</sub>]</code> indicates that the player <code>winner<sub>i</sub></code> defeated player <code>loser<sub>i</sub></code> in a match.</p>

<p>Return <em>a list </em><code>answer</code><em> of size </em><code>2</code><em> where:</em></p>

<ul>
	<li><code>answer[0]</code> is a list of all players that have <strong>not</strong> lost any matches.</li>
	<li><code>answer[1]</code> is a list of all players that have lost exactly <strong>one</strong> match.</li>
</ul>

<p>The values in the two lists should be returned in <strong>increasing</strong> order.</p>

<p><strong>Note:</strong></p>

<ul>
	<li>You should only consider the players that have played <strong>at least one</strong> match.</li>
	<li>The testcases will be generated such that <strong>no</strong> two matches will have the <strong>same</strong> outcome.</li>
</ul>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> matches = [[1,3],[2,3],[3,6],[5,6],[5,7],[4,5],[4,8],[4,9],[10,4],[10,9]]
<strong>Output:</strong> [[1,2,10],[4,5,7,8]]
<strong>Explanation:</strong>
Players 1, 2, and 10 have not lost any matches.
Players 4, 5, 7, and 8 each have lost one match.
Players 3, 6, and 9 each have lost two matches.
Thus, answer[0] = [1,2,10] and answer[1] = [4,5,7,8].
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> matches = [[2,3],[1,3],[5,4],[6,4]]
<strong>Output:</strong> [[1,2,5,6],[]]
<strong>Explanation:</strong>
Players 1, 2, 5, and 6 have not lost any matches.
Players 3 and 4 each have lost two matches.
Thus, answer[0] = [1,2,5,6] and answer[1] = [].
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= matches.length &lt;= 10<sup>5</sup></code></li>
	<li><code>matches[i].length == 2</code></li>
	<li><code>1 &lt;= winner<sub>i</sub>, loser<sub>i</sub> &lt;= 10<sup>5</sup></code></li>
	<li><code>winner<sub>i</sub> != loser<sub>i</sub></code></li>
	<li>All <code>matches[i]</code> are <strong>unique</strong>.</li>
</ul>

class Solution {
public:
    vector<vector<int>> findWinners(vector<vector<int>>& matches) {
        int n = matches.size();
        // set<int> winner;
        // set<int> looser;
        // for(int i =0;i<n;i++){
        //     for(int j=0;j<2;j++){
        //         if(j==0){
        //             winner.insert(v[i][j]);
        //         }
        //         else{
        //             looser.insert(v[i][j]);
        //         }
        //     }
        // }
        // set<int> intersectionSet;
        //  set_intersection(winner.begin(), winner.end(), looser.begin(), looser.end(),
        //                    inserter(intersectionSet, intersectionSet.begin()));
        //  set<int> differenceSet;
        //  set_difference(winner.begin(), winner.end(), intersectionSet.begin(), intersectionSet.end(),
        //                  inserter(differenceSet, differenceSet.begin()));  

        unordered_map<int,int> winner;
        unordered_map<int,int> looser;

        for(int i =0;i<n;i++){
            winner[matches[i][0]]++;
            looser[matches[i][1]]++;
        }
        unordered_set<int> intersection;
         for (const auto &pair : winner) {
        if (looser.find(pair.first) != looser.end()) {
            intersection.insert(pair.first);
        }
    }
        vector<int> notlost;
        vector<int> onelost;
          
         for (const auto &pair : winner) {
        if (intersection.find(pair.first) == intersection.end()) {
              notlost.push_back(pair.first);
        }
    }
     for(auto i: looser){
        if(i.second == 1){
            onelost.push_back(i.first);
        }
     }


    //      for (auto i : notlost) {
    //      cout <<  i<<" ";
    // }
    // cout<<endl;
    // for (auto i : onelost) {
    //      cout <<i << " ";
    // }

    sort(notlost.begin(),notlost.end());
    sort(onelost.begin(),onelost.end());
    matches.clear();
    matches.push_back(notlost);
    matches.push_back(onelost);
        return matches;                
    }
};
177830