結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
9,520 KB
testcase_01 AC 6 ms
9,476 KB
testcase_02 AC 4 ms
9,412 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 5 ms
9,524 KB
testcase_06 AC 5 ms
9,468 KB
testcase_07 WA -
testcase_08 AC 341 ms
32,340 KB
testcase_09 AC 315 ms
30,688 KB
testcase_10 AC 346 ms
32,788 KB
testcase_11 AC 257 ms
27,384 KB
testcase_12 AC 292 ms
27,776 KB
testcase_13 AC 302 ms
28,588 KB
testcase_14 AC 351 ms
33,368 KB
testcase_15 AC 348 ms
32,928 KB
testcase_16 AC 318 ms
31,508 KB
testcase_17 AC 260 ms
28,420 KB
testcase_18 AC 316 ms
28,504 KB
testcase_19 AC 299 ms
32,464 KB
testcase_20 AC 299 ms
31,048 KB
testcase_21 AC 311 ms
32,880 KB
testcase_22 AC 373 ms
33,652 KB
testcase_23 AC 373 ms
33,764 KB
testcase_24 AC 324 ms
31,524 KB
testcase_25 AC 351 ms
32,548 KB
testcase_26 AC 373 ms
33,640 KB
testcase_27 AC 367 ms
33,748 KB
testcase_28 AC 372 ms
34,112 KB
testcase_29 AC 376 ms
34,112 KB
testcase_30 AC 346 ms
33,060 KB
testcase_31 AC 373 ms
34,112 KB
testcase_32 AC 320 ms
33,484 KB
testcase_33 AC 326 ms
31,496 KB
testcase_34 AC 372 ms
34,244 KB
testcase_35 AC 354 ms
32,440 KB
testcase_36 AC 371 ms
34,096 KB
testcase_37 AC 374 ms
34,112 KB
testcase_38 AC 327 ms
30,832 KB
testcase_39 AC 290 ms
29,108 KB
testcase_40 AC 329 ms
30,580 KB
testcase_41 AC 305 ms
29,424 KB
testcase_42 AC 327 ms
30,708 KB
testcase_43 AC 6 ms
9,484 KB
testcase_44 AC 5 ms
9,456 KB
testcase_45 AC 265 ms
26,328 KB
testcase_46 AC 281 ms
26,228 KB
testcase_47 AC 270 ms
26,188 KB
testcase_48 AC 281 ms
26,236 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;
        if(ans[0]>ans[1]){
            ans.pb(ans[0]);
            REP(i,1,n){
                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