Source Code
#include <bits/stdc++.h>

using namespace std;

int main()
{
    vector<pair<int,int>>v;
    vector<pair<pair<int,int>,int>>ve;
    vector<int>vec;
    int n,m,a,m1,m2,m3;
    cin>>n>>m;
    for(int i = 1 ; i <= n;i++)
    {
        cin>>a;
        if(a==1)
        {
        cin>>m1;
        v.push_back({m1,i});
        }
        else
        {
        cin>>m2>>m3;
        if(m2!=m3-1&&m3!=m2-1)
        {
            cout<<-1;
            return 0;
        }
        ve.push_back({{max(m2,m3),min(m2,m3)},i});
        }
    }
   sort(v.begin(),v.end());
   sort(ve.begin(),ve.end());
   for(auto i : v)
   vec.push_back(i.second);
   for(auto i : ve)
   vec.push_back(i.second);
   for(auto i :vec)
   cout<<i<<" ";
}
Copy
Gym moathhamudah
GNU G++17
1 ms
256 KB
Wrong Answer