結果

問題 No.1647 Travel in Mitaru city 2
ユーザー fumofumofunifumofumofuni
提出日時 2021-08-13 21:59:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,868 bytes
コンパイル時間 2,179 ms
コンパイル使用メモリ 203,708 KB
実行使用メモリ 22,236 KB
最終ジャッジ日時 2024-04-14 17:49:39
合計ジャッジ時間 13,672 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,524 KB
testcase_01 AC 6 ms
9,528 KB
testcase_02 AC 5 ms
9,456 KB
testcase_03 AC 5 ms
9,524 KB
testcase_04 WA -
testcase_05 AC 5 ms
9,516 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 128 ms
21,192 KB
testcase_09 AC 121 ms
19,896 KB
testcase_10 AC 128 ms
21,240 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 130 ms
21,652 KB
testcase_15 AC 128 ms
21,352 KB
testcase_16 AC 119 ms
20,568 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 135 ms
21,668 KB
testcase_23 AC 140 ms
21,776 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 132 ms
21,904 KB
testcase_27 AC 141 ms
21,896 KB
testcase_28 AC 138 ms
22,128 KB
testcase_29 AC 134 ms
22,128 KB
testcase_30 WA -
testcase_31 AC 131 ms
22,128 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 139 ms
22,124 KB
testcase_35 AC 123 ms
20,692 KB
testcase_36 AC 133 ms
22,128 KB
testcase_37 AC 136 ms
22,124 KB
testcase_38 AC 122 ms
19,092 KB
testcase_39 WA -
testcase_40 AC 122 ms
18,896 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 6 ms
9,520 KB
testcase_44 AC 6 ms
9,480 KB
testcase_45 WA -
testcase_46 AC 112 ms
14,768 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 101 ms
14,940 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 ans;
bool dfs(ll v,ll p){
    seen[v]=1;
    for(auto nv:g[v]){
        if(nv.first==p)continue;
        if(seen[nv.first]){
            ans.push_back(nv.second);
            return true;
        }
        if(dfs(nv.first,v)){
            ans.push_back(nv.second);
            return true;
        }
    }
    return false;
}
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;
        if(dfs(i,-1)){
            cout << ans.size() <<endl;
            rev(all(ans));
            for(auto p:ans)cout << p <<" ";cout << endl;
            return 0;
        }
    }
    cout << -1 <<endl;
}      

0