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,c=0;
    cin>>n>>m;
    for(int i = 1 ; i <= n;i++)
    {
        cin>>a;
        if(a==1)
        {
        cin>>m1;
        v.push_back({m1,i});
        }
        else
        {
        c++;
        cin>>m2>>m3;
        ve.push_back({{max(m2,m3),min(m2,m3)},i});
        }
    }
    if(c==3)
     cout<<-1;
     else
   {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
208 KB
Wrong Answer