結果
| 問題 |
No.1647 Travel in Mitaru city 2
|
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2021-08-13 22:25:08 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,666 bytes |
| コンパイル時間 | 4,129 ms |
| コンパイル使用メモリ | 256,912 KB |
| 最終ジャッジ日時 | 2025-01-23 20:02:05 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 WA * 40 |
ソースコード
#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;
}
Kude