結果

問題 No.1647 Travel in Mitaru city 2
ユーザー auauaauaua
提出日時 2021-08-13 22:16:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,636 bytes
コンパイル時間 2,025 ms
コンパイル使用メモリ 176,628 KB
実行使用メモリ 34,244 KB
最終ジャッジ日時 2024-04-14 18:26:47
合計ジャッジ時間 20,538 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
9,460 KB
testcase_01 AC 5 ms
9,396 KB
testcase_02 AC 5 ms
9,408 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 6 ms
9,624 KB
testcase_06 AC 7 ms
9,476 KB
testcase_07 WA -
testcase_08 AC 353 ms
32,220 KB
testcase_09 AC 314 ms
30,812 KB
testcase_10 AC 363 ms
32,660 KB
testcase_11 AC 271 ms
27,312 KB
testcase_12 AC 297 ms
27,888 KB
testcase_13 AC 311 ms
28,576 KB
testcase_14 AC 368 ms
33,196 KB
testcase_15 AC 366 ms
33,056 KB
testcase_16 AC 335 ms
31,508 KB
testcase_17 AC 280 ms
28,428 KB
testcase_18 AC 334 ms
28,400 KB
testcase_19 AC 329 ms
32,308 KB
testcase_20 AC 322 ms
30,960 KB
testcase_21 AC 325 ms
32,788 KB
testcase_22 AC 380 ms
33,652 KB
testcase_23 AC 377 ms
33,636 KB
testcase_24 AC 337 ms
31,432 KB
testcase_25 AC 356 ms
32,672 KB
testcase_26 AC 385 ms
33,524 KB
testcase_27 AC 378 ms
33,748 KB
testcase_28 AC 385 ms
34,244 KB
testcase_29 AC 384 ms
34,108 KB
testcase_30 AC 347 ms
32,932 KB
testcase_31 AC 378 ms
34,108 KB
testcase_32 AC 323 ms
33,540 KB
testcase_33 AC 328 ms
31,600 KB
testcase_34 AC 381 ms
34,112 KB
testcase_35 AC 359 ms
32,444 KB
testcase_36 AC 392 ms
34,112 KB
testcase_37 AC 385 ms
34,240 KB
testcase_38 AC 355 ms
30,860 KB
testcase_39 AC 311 ms
29,100 KB
testcase_40 AC 412 ms
30,576 KB
testcase_41 AC 330 ms
29,560 KB
testcase_42 AC 356 ms
30,676 KB
testcase_43 AC 6 ms
9,568 KB
testcase_44 AC 6 ms
9,568 KB
testcase_45 AC 289 ms
26,136 KB
testcase_46 AC 302 ms
26,156 KB
testcase_47 AC 289 ms
26,468 KB
testcase_48 AC 298 ms
26,220 KB
testcase_49 WA -
testcase_50 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
        rep(i,ans.size()-1){
            cout<<ma[mp(ans[i],ans[i+1])]+1<<' ';
        }
        cout<<endl;
    }
}
0