結果

問題 No.1647 Travel in Mitaru city 2
ユーザー auauaauaua
提出日時 2021-08-13 22:26:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 332 ms / 2,500 ms
コード長 1,831 bytes
コンパイル時間 1,829 ms
コンパイル使用メモリ 175,880 KB
実行使用メモリ 34,240 KB
最終ジャッジ日時 2024-04-21 04:52:43
合計ジャッジ時間 17,176 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
9,484 KB
testcase_01 AC 6 ms
9,472 KB
testcase_02 AC 6 ms
9,600 KB
testcase_03 AC 6 ms
9,472 KB
testcase_04 AC 8 ms
9,856 KB
testcase_05 AC 6 ms
9,456 KB
testcase_06 AC 6 ms
9,600 KB
testcase_07 AC 11 ms
9,984 KB
testcase_08 AC 308 ms
32,360 KB
testcase_09 AC 265 ms
30,684 KB
testcase_10 AC 299 ms
32,664 KB
testcase_11 AC 237 ms
27,380 KB
testcase_12 AC 253 ms
27,904 KB
testcase_13 AC 256 ms
28,656 KB
testcase_14 AC 320 ms
33,244 KB
testcase_15 AC 297 ms
32,928 KB
testcase_16 AC 283 ms
31,380 KB
testcase_17 AC 238 ms
28,416 KB
testcase_18 AC 271 ms
28,544 KB
testcase_19 AC 262 ms
32,384 KB
testcase_20 AC 268 ms
31,104 KB
testcase_21 AC 283 ms
32,768 KB
testcase_22 AC 332 ms
33,532 KB
testcase_23 AC 329 ms
33,636 KB
testcase_24 AC 282 ms
31,360 KB
testcase_25 AC 304 ms
32,544 KB
testcase_26 AC 320 ms
33,640 KB
testcase_27 AC 316 ms
33,752 KB
testcase_28 AC 317 ms
34,176 KB
testcase_29 AC 329 ms
34,236 KB
testcase_30 AC 313 ms
32,932 KB
testcase_31 AC 314 ms
34,108 KB
testcase_32 AC 280 ms
33,488 KB
testcase_33 AC 282 ms
31,488 KB
testcase_34 AC 322 ms
34,240 KB
testcase_35 AC 289 ms
32,444 KB
testcase_36 AC 318 ms
34,112 KB
testcase_37 AC 325 ms
34,108 KB
testcase_38 AC 282 ms
30,848 KB
testcase_39 AC 260 ms
29,184 KB
testcase_40 AC 287 ms
30,720 KB
testcase_41 AC 268 ms
29,528 KB
testcase_42 AC 285 ms
30,720 KB
testcase_43 AC 6 ms
9,468 KB
testcase_44 AC 6 ms
9,472 KB
testcase_45 AC 233 ms
26,240 KB
testcase_46 AC 254 ms
26,188 KB
testcase_47 AC 244 ms
26,240 KB
testcase_48 AC 256 ms
26,304 KB
testcase_49 AC 240 ms
26,328 KB
testcase_50 AC 243 ms
26,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    }
}
0