結果

問題 No.1647 Travel in Mitaru city 2
ユーザー KudeKude
提出日時 2021-08-13 22:25:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,666 bytes
コンパイル時間 5,437 ms
コンパイル使用メモリ 260,928 KB
実行使用メモリ 27,560 KB
最終ジャッジ日時 2024-04-14 18:40:30
合計ジャッジ時間 15,596 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,948 KB
testcase_03 AC 2 ms
6,948 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 2 ms
6,940 KB
testcase_44 AC 4 ms
8,560 KB
testcase_45 WA -
testcase_46 AC 72 ms
14,588 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, n;
    cin >> h >> w >> n;
    vector<vector<P>> to(h + w);
    rep(i, n) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        to[x].emplace_back(h + y, i + 1);
        to[h + y].emplace_back(x, i + 1);
    }
    vector<char> visited(h + w);
    vector<P> path;
    auto dfs = [&](auto&& self, int u, int p=-1) -> void {
        if (visited[u]) {
            VI ans;
            ans.push_back(p);
            while(path.back().first != u) {
                ans.push_back(path.back().second);
                path.pop_back();
            }
            if (u >= h) {
                rotate(ans.begin(), ans.begin() + 1, ans.end());
            }
            int sz = ans.size();
            cout << sz << '\n';
            rep(i, sz) cout << ans[i] << " \n"[i + 1 == sz];
            exit(0);
        }
        visited[u] = true;
        path.emplace_back(u, p);
        for(auto [v, eid]: to[u]) if (eid != p) {
            self(self, v, eid);
        }
    };

    rep(i, h) if (!visited[i]) dfs(dfs, i);
    cout << -1 << endl;
}
0