#include #pragma GCC optimize("Ofast") #define _GLIBCXX_DEBUG using namespace std; using std::cout; using std::cin; using std::endl; using ll=long long; using ld=long double; ll ILL=1167167167167167167; const int INF=2100000000; ll mod=998244353; #define rep(i,a) for (ll i=0;i using _pq = priority_queue, greater>; template ll LB(vector &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template ll UB(vector &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;} template bool chmax(T &a,const T &b){if(a void So(vector &v) {sort(v.begin(),v.end());} template void Sore(vector &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";} //おちこんだりもしたけれど、私はげんきです。 int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N,H,W; cin>>H>>W>>N; vector> G(N+H+W); vector x(N),y(N); rep(i,N){ cin>>x[i]>>y[i]; x[i]--,y[i]--; G[x[i]+N].push_back(i); G[y[i]+H+N].push_back(i); G[i].push_back(x[i]+N); G[i].push_back(y[i]+N+H); } vector par(N+H+W,-1); vector ans1,ans2; int J=0,A,B; rep(i,N){ if(par[i]!=-1) continue; par[i]=-2; queue q; q.push(i); while(!q.empty()){ int a=q.front(); q.pop(); for(auto x:G[a]){ if(par[x]==-1){ par[x]=a; q.push(x); } else if(x==par[a]) continue; else{ A=x,B=a; J=1; break; } } } if(J) break; } if(J==0){ cout<<"-1\n"; return 0; } while(A>=0){ ans1.push_back(A); A=par[A]; } while(B>=0){ ans2.push_back(B); B=par[B]; } reverse(ans1.begin(),ans1.end()); reverse(ans2.begin(),ans2.end()); int ind=0; while(ans1[ind]==ans2[ind]) ind++; vector ans; for(int i=ind-1;i=ind;i--){ if(ans2[i]=4); while(y[start]!=y[start+1]) start++; rep(i,M){ if(i!=0) cout<<" "; cout<