結果
| 問題 |
No.1647 Travel in Mitaru city 2
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2021-08-13 23:06:47 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,794 bytes |
| コンパイル時間 | 3,176 ms |
| コンパイル使用メモリ | 122,228 KB |
| 最終ジャッジ日時 | 2025-01-23 20:59:37 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 WA * 5 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
#include <atcoder/fenwicktree>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(n); i++)
struct Edge{ int to; int i; };
int H,W,N;
vector<vector<Edge>> E;
int main() {
cin >> H >> W >> N;
E.resize(H+W);
rep(i,N){
int y,x; cin >> y >> x; y--; x--;
E[y].push_back({H+x,i});
E[H+x].push_back({y,i});
}
vector<int> D(H+W,-1);
vector<int> P(H+W,-1);
vector<int> Pi(H+W,-1);
vector<int> ans;
for(int s=0; s<=H; s++) if(D[s] == -1){
P[s] = -2;
D[s] = 0;
vector<int> I;
I.push_back(s);
rep(i,I.size()){
int p = I[i];
for(auto e : E[p]){
if(D[e.to] == -1){
D[e.to] = D[p] + 1;
P[e.to] = p;
Pi[e.to] = e.i;
I.push_back(e.to);
}
if(D[p] != 0) if(D[e.to] == D[p] + 1) if(P[e.to] != p){
vector<int> ans1 = {e.i};
int x1 = p;
vector<int> ans2 = {Pi[e.to]};
int x2 = P[e.to];
while(x1 != x2){
ans1.push_back(Pi[x1]);
ans2.push_back(Pi[x2]);
x1 = P[x1];
x2 = P[x2];
}
while(ans1.size()){
ans.push_back(ans1.back());
ans1.pop_back();
}
for(auto a : ans2) ans.push_back(a);
cout << ans.size() << "\n";
rep(i,ans.size()){
if(i) cout << " ";
cout << (ans[i]+1);
}
cout << "\n";
return 0;
}
}
}
for(int p : I) D[p] = -2;
}
cout << "-1\n";
return 0;
}
struct ios_do_not_sync{
ios_do_not_sync(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
} ios_do_not_sync_instance;
Nachia