結果

問題 No.1647 Travel in Mitaru city 2
ユーザー fumofumofunifumofumofuni
提出日時 2021-08-13 22:10:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,898 bytes
コンパイル時間 2,446 ms
コンパイル使用メモリ 202,488 KB
実行使用メモリ 25,124 KB
最終ジャッジ日時 2024-04-14 18:12:47
合計ジャッジ時間 14,053 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
11,060 KB
testcase_01 AC 6 ms
11,076 KB
testcase_02 AC 7 ms
11,004 KB
testcase_03 AC 7 ms
11,060 KB
testcase_04 WA -
testcase_05 AC 7 ms
11,128 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 131 ms
23,708 KB
testcase_09 AC 122 ms
22,300 KB
testcase_10 AC 132 ms
23,804 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 138 ms
24,188 KB
testcase_15 AC 132 ms
23,840 KB
testcase_16 AC 121 ms
23,180 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 136 ms
24,356 KB
testcase_23 AC 141 ms
24,612 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 139 ms
24,356 KB
testcase_27 AC 134 ms
24,864 KB
testcase_28 AC 144 ms
25,124 KB
testcase_29 AC 137 ms
24,988 KB
testcase_30 WA -
testcase_31 AC 144 ms
24,996 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 140 ms
24,992 KB
testcase_35 AC 131 ms
22,940 KB
testcase_36 AC 139 ms
24,988 KB
testcase_37 AC 131 ms
24,988 KB
testcase_38 AC 121 ms
21,556 KB
testcase_39 WA -
testcase_40 AC 125 ms
21,284 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 7 ms
11,120 KB
testcase_44 AC 7 ms
11,108 KB
testcase_45 WA -
testcase_46 AC 118 ms
16,464 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 98 ms
16,444 KB
testcase_50 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={0,1,-1,0,1,1,-1,-1,0};
const ll dx[9]={1,0,0,-1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

vvpl g(200010);
vl seen(200010);
vl fin(200010);
vl hist;
ll pos=-1;
void dfs(ll v,ll p){
  seen[v]=1;
  //hist.push_back(v);
  for(auto nv:g[v]){
    if(nv.first==p)continue;
    if(fin[nv.first])continue;
    if(seen[nv.first]&&!fin[nv.first]){
      pos=nv.first;
      hist.push_back(nv.second);
      return;
    }
    hist.push_back(nv.second);
    dfs(nv.first,v);
    if(pos!=-1)return;
    hist.pop_back();
  }
  fin[v]=1;
}
int main(){
    ll h,w,n;cin >> h >> w >>n;
    rep(i,n){
        ll x,y;cin >> x >> y;x--;y--;
        g[x].push_back({y+h,i+1});
        g[y+h].push_back({x,i+1});
    }
    rep(i,h){
      if(seen[i])continue;
      dfs(i,-1);
      if(hist.size()){
        cout << hist.size() <<endl;
        for(auto p:hist)cout << p <<" ";cout << endl;
        return 0;
      }
    }
    cout << -1 <<endl;
}      

0