82B - Sets - CodeForces Solution


constructive algorithms hashing implementation *1700

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#define ll long long
#define nl '\n'
using namespace std;

void sol() {
    ll n;
    cin >> n;
    vector<vector<ll>> v(n * (n - 1) / 2);
    for (int i = 0; i < n * (n - 1) / 2; ++i) {
        ll k;
        cin >> k;
        v[i].resize(k);
        for (ll j = 0; j < k; ++j){
            cin >> v[i][j];
        }
    }
    if (n == 2) {
        cout << "1 " << v[0][0] << "\n";
        cout << (ll)v[0].size() - 1 << " ";
        for (ll i = 1; i < (ll)v[0].size(); ++i){
            cout << v[0][i] << " ";
        }
        return ;
    }
    unordered_map<ll, vector<ll>> x;
    map<vector<ll>, vector<ll>> y;
    for (int i = 0; i < n * (n - 1) / 2; ++i) {
        for (auto z : v[i]) x[z].push_back(i);
    }
    for (auto p : x) y[p.second].push_back(p.first);
    for (auto p : y) {
        cout << (ll)p.second.size() << " ";
        for (int l = 0; l < (ll)p.second.size(); ++l) cout << p.second[l] << " ";
        cout << nl;
    }

}






int main() {
    int tc = 1;
    //cin >> tc;
    while (tc--) {
        sol();
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

1506A - Strange Table
456A - Laptops
855B - Marvolo Gaunt's Ring
1454A - Special Permutation
1359A - Berland Poker
459A - Pashmak and Garden
1327B - Princesses and Princes
1450F - The Struggling Contestant
1399B - Gifts Fixing
1138A - Sushi for Two
982C - Cut 'em all
931A - Friends Meeting
1594A - Consecutive Sum Riddle
1466A - Bovine Dilemma
454A - Little Pony and Crystal Mine
2A - Winner
1622B - Berland Music
1139B - Chocolates
1371A - Magical Sticks
1253A - Single Push
706B - Interesting drink
1265A - Beautiful String
214A - System of Equations
287A - IQ Test
1108A - Two distinct points
1064A - Make a triangle
1245C - Constanze's Machine
1005A - Tanya and Stairways
1663F - In Every Generation
1108B - Divisors of Two Integers