結果

問題 No.1647 Travel in Mitaru city 2
ユーザー 👑 potato167potato167
提出日時 2021-08-13 22:32:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,370 bytes
コンパイル時間 2,496 ms
コンパイル使用メモリ 217,444 KB
実行使用メモリ 26,724 KB
最終ジャッジ日時 2024-04-14 18:50:12
合計ジャッジ時間 15,547 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 5 ms
6,940 KB
testcase_08 AC 174 ms
25,512 KB
testcase_09 WA -
testcase_10 AC 168 ms
25,676 KB
testcase_11 AC 164 ms
24,784 KB
testcase_12 AC 172 ms
25,508 KB
testcase_13 AC 182 ms
25,528 KB
testcase_14 AC 182 ms
26,052 KB
testcase_15 WA -
testcase_16 AC 167 ms
24,824 KB
testcase_17 AC 173 ms
24,772 KB
testcase_18 WA -
testcase_19 AC 183 ms
26,432 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 189 ms
26,524 KB
testcase_23 AC 183 ms
26,540 KB
testcase_24 WA -
testcase_25 AC 189 ms
26,596 KB
testcase_26 AC 192 ms
26,540 KB
testcase_27 AC 193 ms
26,672 KB
testcase_28 WA -
testcase_29 AC 196 ms
26,592 KB
testcase_30 AC 189 ms
26,556 KB
testcase_31 AC 199 ms
26,596 KB
testcase_32 AC 186 ms
26,044 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 186 ms
26,596 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 179 ms
25,348 KB
testcase_40 WA -
testcase_41 AC 179 ms
25,780 KB
testcase_42 AC 189 ms
25,772 KB
testcase_43 AC 2 ms
6,940 KB
testcase_44 AC 6 ms
8,544 KB
testcase_45 AC 155 ms
25,496 KB
testcase_46 AC 187 ms
25,708 KB
testcase_47 AC 155 ms
25,524 KB
testcase_48 WA -
testcase_49 AC 150 ms
25,660 KB
testcase_50 AC 162 ms
25,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=1167167167167167167;
const int INF=2100000000;
ll mod=998244353;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}


//おちこんだりもしたけれど、私はげんきです。
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int N,H,W;
	cin>>H>>W>>N;
	vector<vector<int>> G(N+H+W);
	vector<int> x(N),y(N);
	map<pair<int,int>,int> m;
	rep(i,N){
		cin>>x[i]>>y[i];
		x[i]--,y[i]--;
		m[{x[i],y[i]}]=i;
		G[x[i]+N].push_back(i);
		G[y[i]+H+N].push_back(i);
		G[i].push_back(x[i]+N);
		G[i].push_back(y[i]+N+H);
	}
	vector<int> par(N+H+W,-1);
	vector<int> ans1,ans2;
	int J=0,A,B;
	rep(i,N){
		if(par[i]!=-1) continue;
		par[i]=-2;
		queue<int> q;
		q.push(i);
		while(!q.empty()){
			int a=q.front();
			q.pop();
			for(auto x:G[a]){
				if(par[x]==-1){
					par[x]=a;
					q.push(x);
				}
				else if(x==par[a]) continue;
				else{
					A=x,B=a;
					J=1;
					break;
				}
			}
		}
		if(J) break;
	}
	if(J==0){
		cout<<"-1\n";
		return 0;
	}
	while(A>=0){
		ans1.push_back(A);
		A=par[A];
	}
	while(B>=0){
		ans2.push_back(B);
		B=par[B];
	}
	reverse(ans1.begin(),ans1.end());
	reverse(ans2.begin(),ans2.end());
	int ind=0;
	while(ans1[ind]==ans2[ind]) ind++;
	vector<ll> ans;
	for(int i=ind-1;i<ans1.size();i++){
		if(ans1[i]<N) ans.push_back(ans1[i]);
	}
	for(int i=ans2.size()-1;i>=ind;i--){
		if(ans2[i]<N) ans.push_back(ans2[i]);
	}
	int start=0;
	int M=ans.size();
	cout<<M<<endl;
	while(x[start]!=x[start+1]) start+=1;
	rep(i,M){
		if(i!=0) cout<<" ";
		cout<<ans[(i+start)%M]+1;
	}
	cout<<endl<<endl;
}

0