結果
問題 | No.1647 Travel in Mitaru city 2 |
ユーザー | monnu |
提出日時 | 2021-08-29 20:45:17 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,333 bytes |
コンパイル時間 | 3,606 ms |
コンパイル使用メモリ | 232,600 KB |
実行使用メモリ | 21,972 KB |
最終ジャッジ日時 | 2024-05-02 00:00:44 |
合計ジャッジ時間 | 15,872 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 102 ms
20,356 KB |
testcase_09 | AC | 90 ms
18,928 KB |
testcase_10 | AC | 91 ms
20,448 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 96 ms
20,804 KB |
testcase_15 | AC | 97 ms
20,544 KB |
testcase_16 | AC | 98 ms
19,852 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 103 ms
21,244 KB |
testcase_23 | AC | 104 ms
21,352 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 104 ms
21,376 KB |
testcase_27 | AC | 107 ms
21,636 KB |
testcase_28 | AC | 107 ms
21,888 KB |
testcase_29 | AC | 103 ms
21,828 KB |
testcase_30 | WA | - |
testcase_31 | AC | 97 ms
21,876 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | AC | 98 ms
21,972 KB |
testcase_35 | AC | 95 ms
20,028 KB |
testcase_36 | AC | 105 ms
21,888 KB |
testcase_37 | AC | 99 ms
21,888 KB |
testcase_38 | AC | 90 ms
18,816 KB |
testcase_39 | WA | - |
testcase_40 | AC | 92 ms
18,816 KB |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 2 ms
5,376 KB |
testcase_44 | AC | 6 ms
9,600 KB |
testcase_45 | WA | - |
testcase_46 | AC | 89 ms
14,464 KB |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
ソースコード
#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'; }