#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll MOD = 1e9 + 7 ;
ll bigMod(ll x,ll y){
if (y == 0)return 1;
if (y == 1)return x;
ll res = bigMod(x , y / 2LL);
res *= res;
res %= MOD;
if (y % 2){
res *= x;
res %= MOD;
}
return res;
}
ll fac[1000005];
ll choose(ll x,ll y){
if (x == y)return 1;
if (y > x)return 0;
if (y == 0)return 1;
ll up = fac[x];
ll down = fac[y] * fac[x-y];
down %= MOD;
ll ret = up * bigMod(down , MOD - 2);
ret %= MOD;
return ret;
}
ll n , m;
map<pair<ll,ll> , bool > ma;
vector<int> v[500005];
int last[500005];
int main()
{
ios::sync_with_stdio(0);
cin >> n >> m;
memset(last , -1, sizeof(last));
vector<pair<ll,pair<ll , ll >> > v;
for (int i=0;i<n;i++){
int x;
cin >> x;
ll y , z;
if (x == 1){
cin >> y;
z = y;
}
else {
cin >> y >> z;
}
if (y > z)swap(y,z);
v.push_back({y,{z,i+1}});
}
sort(v.begin() , v.end());
int last1 = v[0].first;
int last2 = v[0].second.first;
last[last1] = 1;
last[last2] = 1;
int idx = v[0].second.second;
vector<int> ans;
ans.push_back(idx);
bool bla = 0;
for (int i=1;i<v.size();i++){
if ((last[v[i].first] != -1 && last[v[i].first] != i) || (last[v[i].second.first] != -1 && last[v[i].second.first] != i)){
bla = 1;
// cout << "blaaa " << v[i].second.second << " " << last1 << " " << last2 << " " << v[i].first << " " << v[i].second.first << endl;
}
last1 = v[i].first;
last2 = v[i].second.first;
last[last1] = i+1;
last[last2] = i+1;
int idx = v[i].second.second;
ans.push_back(idx);
}
if (!bla){
for (int x : ans)cout << x << " ";
cout << endl;
}
else cout << -1 << endl;
return 0;
}
Copy