結果

問題 No.1647 Travel in Mitaru city 2
ユーザー 蜜蜂蜜蜂
提出日時 2021-07-27 13:55:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,970 bytes
コンパイル時間 4,318 ms
コンパイル使用メモリ 232,572 KB
実行使用メモリ 37,084 KB
最終ジャッジ日時 2024-04-14 15:44:10
合計ジャッジ時間 21,269 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,812 KB
testcase_01 AC 5 ms
6,812 KB
testcase_02 AC 4 ms
6,940 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 6 ms
6,940 KB
testcase_05 AC 5 ms
6,944 KB
testcase_06 AC 4 ms
6,944 KB
testcase_07 AC 7 ms
7,168 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 247 ms
29,968 KB
testcase_13 AC 233 ms
30,580 KB
testcase_14 WA -
testcase_15 AC 309 ms
35,156 KB
testcase_16 AC 279 ms
33,524 KB
testcase_17 AC 234 ms
30,456 KB
testcase_18 AC 243 ms
30,836 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 324 ms
36,076 KB
testcase_24 AC 276 ms
34,128 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 331 ms
37,084 KB
testcase_29 WA -
testcase_30 AC 307 ms
35,464 KB
testcase_31 WA -
testcase_32 AC 291 ms
36,432 KB
testcase_33 AC 297 ms
34,380 KB
testcase_34 AC 326 ms
36,956 KB
testcase_35 AC 309 ms
34,944 KB
testcase_36 WA -
testcase_37 AC 337 ms
36,956 KB
testcase_38 AC 290 ms
33,016 KB
testcase_39 AC 254 ms
31,136 KB
testcase_40 AC 286 ms
32,756 KB
testcase_41 WA -
testcase_42 AC 288 ms
32,956 KB
testcase_43 AC 4 ms
6,944 KB
testcase_44 AC 7 ms
11,136 KB
testcase_45 WA -
testcase_46 AC 225 ms
28,384 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

//g++ 1.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;

#define fi first
#define se second
#define pb push_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)

vi seen(410000,0);
vi fin(410000,0);
vi hist;
int pos=-1;

void dfs(vvi &g,int now,int p){
  seen[now]=1;
  hist.pb(now);

  for(int next:g[now]){
    if(next==p){
      continue;
    }
    if(fin[next]==1){
      continue;
    }
    if(seen[next]==1&&fin[next]==0){
      pos=next;
      return;
    }

    dfs(g,next,now);

    if(pos!=-1){
      return;
    }
  }

  hist.pop_back();
  fin[now]=1;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int h,w,n;
  cin>>h>>w>>n;

  vvi g(h+w);
  vector<pair<int,int>> place(n);
  map<pair<int,int>,int> inv;

  rep(i,0,n){
    int x,y;
    cin>>x>>y;
    x--;y--;
    place[i].fi=x,place[i].se=y;
    g[x].pb(h+y);
    g[h+y].pb(x);
    inv[{x,h+y}]=i;
    inv[{h+y,x}]=i;
  }

  dfs(g,0,-1);

  if(pos==-1){
    cout<<"-1\n";
    return 0;
  }

  vi cycle;
  while(!hist.empty()){
    int t=hist[hist.size()-1];
    cycle.pb(t);
    hist.pop_back();
    if(t==pos){
      break;
    }
  }

  vi ans;
  rep(i,0,cycle.size()){
    int now=cycle[i],next=cycle[(i+1)%cycle.size()];
    ans.pb(inv[{now,next}]);
  }

  cout<<ans.size()<<"\n";

  if(place[ans[0]].se==place[ans[1]].se){
    rep(i,0,ans.size()){
      cout<<ans[i]+1<<" ";
    }
    cout<<"\n";
  }
  else{
    rep(i,1,ans.size()+1){
      cout<<ans[i%ans.size()]+1<<" ";
    }
    cout<<"\n";
  }
}
0