結果
問題 |
No.1647 Travel in Mitaru city 2
|
ユーザー |
![]() |
提出日時 | 2021-08-13 22:26:54 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 319 ms / 2,500 ms |
コード長 | 1,831 bytes |
コンパイル時間 | 3,406 ms |
コンパイル使用メモリ | 181,040 KB |
実行使用メモリ | 34,116 KB |
最終ジャッジ日時 | 2024-10-13 03:18:56 |
合計ジャッジ時間 | 15,536 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 48 |
ソースコード
#include<bits/stdc++.h> using namespace std; //#define int long long #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' //#define vec vector<ll> //#define mat vector<vector<ll> > #define fi first #define se second #define double long double typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> pll; //typedef long double ld; typedef complex<double> Complex; const ll INF=1e9+7; const ll MOD=998244353; const ll inf=INF*INF; const ll mod=MOD; const ll MAX=200010; const double PI=acos(-1.0); typedef vector<vector<ll> > mat; typedef vector<ll> vec; vector<vector<ll> > G(MAX); vector<ll>ans(0); vector<ll>used(MAX); ll st=-1; ll cnt=0; void dfs(ll i, ll p){ used[i]=1; for(auto e:G[i]){ if(e==p)continue; if(used[e]==1){ st=e; ans.pb(e); break; } dfs(e,i); if(st!=-1)break; } if(st==-2)return; if(st!=-1)ans.pb(i); if(st==i)st=-2; } signed main(){ ll h,w,n;cin>>h>>w>>n; map<pll,ll>ma; ll m=-1; rep(i,n){ ll x,y;cin>>x>>y; x--;y--; G[x].pb(h+y); G[h+y].pb(x); ma[mp(x,h+y)]=i; ma[mp(h+y,x)]=i; } rep(i,h+w){ if(used[i])continue; dfs(i,-1); if(st!=-1)break; } if(st==-1){ cout<<-1<<endl; }else{ cout<<ans.size()-1<<endl; if(ans[0]>ans[1]){ ans.pb(ans[1]); REP(i,1,ans.size()-1){ cout<<ma[mp(ans[i],ans[i+1])]+1<<' '; } }else{ rep(i,ans.size()-1){ cout<<ma[mp(ans[i],ans[i+1])]+1<<' '; } } cout<<endl; } }