結果
| 問題 |
No.1647 Travel in Mitaru city 2
|
| コンテスト | |
| ユーザー |
monnu
|
| 提出日時 | 2021-08-29 20:45:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,333 bytes |
| コンパイル時間 | 3,858 ms |
| コンパイル使用メモリ | 233,600 KB |
| 実行使用メモリ | 22,016 KB |
| 最終ジャッジ日時 | 2024-11-22 08:29:50 |
| 合計ジャッジ時間 | 17,528 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 WA * 25 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
#define MOD 998244353
using Graph=vector<vector<pair<int,int>>>;
#define INF 1000000000
#define MAX 200000
vector<int> ans;
bool dfs(Graph &G,int v,int p,vector<int> &seen){
seen[v]=1;
for(auto e:G[v]){
int nv=e.first;
if(nv==p){
continue;
}
if(seen[nv]==1){
ans.push_back(e.second);
return true;
}else{
if(dfs(G,nv,v,seen)){
ans.push_back(e.second);
return true;
}
}
}
return false;
}
int main(){
int H,W,N;
cin>>H>>W>>N;
vector<int> x(N),y(N);
Graph G(H+W);
for(int i=0;i<N;i++){
cin>>x[i]>>y[i];
x[i]--;y[i]--;
G[x[i]].push_back(make_pair(H+y[i],i));
G[H+y[i]].push_back(make_pair(x[i],i));
}
vector<int> seen(H+W,0);
vector<int> prevv(H+W,-1);
for(int i=0;i<H+W;i++){
if(seen[i]==0){
if(dfs(G,i,-1,seen)){
cout<<ans.size()<<'\n';
if(y[ans[0]]==y[ans[1]]){
for(int j=0;j<ans.size();j++){
cout<<ans[j]+1<<' ';
}
cout<<'\n';
}else{
for(int j=0;j<ans.size();j++){
cout<<ans[(j+1)%(int)ans.size()]+1<<' ';
}
cout<<'\n';
}
return 0;
}
}
}
cout<<-1<<'\n';
}
monnu