結果

問題 No.1647 Travel in Mitaru city 2
ユーザー 👑 kmjpkmjp
提出日時 2021-08-13 23:08:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,565 bytes
コンパイル時間 2,259 ms
コンパイル使用メモリ 202,480 KB
実行使用メモリ 29,224 KB
最終ジャッジ日時 2024-04-14 20:10:28
合計ジャッジ時間 9,544 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
13,768 KB
testcase_01 AC 5 ms
13,892 KB
testcase_02 AC 4 ms
13,896 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 5 ms
14,020 KB
testcase_06 AC 6 ms
13,764 KB
testcase_07 WA -
testcase_08 AC 79 ms
27,328 KB
testcase_09 AC 74 ms
25,368 KB
testcase_10 AC 84 ms
27,420 KB
testcase_11 AC 61 ms
22,372 KB
testcase_12 AC 63 ms
21,184 KB
testcase_13 AC 63 ms
23,028 KB
testcase_14 AC 86 ms
27,804 KB
testcase_15 AC 84 ms
27,724 KB
testcase_16 AC 76 ms
26,700 KB
testcase_17 AC 63 ms
23,048 KB
testcase_18 AC 65 ms
22,244 KB
testcase_19 AC 76 ms
27,412 KB
testcase_20 AC 75 ms
25,260 KB
testcase_21 AC 79 ms
27,512 KB
testcase_22 AC 87 ms
28,032 KB
testcase_23 AC 86 ms
28,180 KB
testcase_24 AC 81 ms
25,480 KB
testcase_25 AC 80 ms
26,796 KB
testcase_26 AC 88 ms
28,176 KB
testcase_27 AC 86 ms
28,300 KB
testcase_28 AC 88 ms
28,824 KB
testcase_29 AC 88 ms
28,848 KB
testcase_30 AC 77 ms
27,156 KB
testcase_31 AC 90 ms
29,020 KB
testcase_32 AC 82 ms
28,308 KB
testcase_33 AC 81 ms
25,744 KB
testcase_34 AC 89 ms
28,848 KB
testcase_35 AC 80 ms
26,416 KB
testcase_36 AC 87 ms
29,224 KB
testcase_37 AC 86 ms
29,072 KB
testcase_38 AC 75 ms
24,976 KB
testcase_39 AC 70 ms
22,620 KB
testcase_40 AC 75 ms
24,620 KB
testcase_41 AC 73 ms
22,960 KB
testcase_42 AC 76 ms
24,588 KB
testcase_43 AC 5 ms
13,888 KB
testcase_44 AC 5 ms
13,892 KB
testcase_45 AC 57 ms
19,060 KB
testcase_46 AC 69 ms
19,520 KB
testcase_47 AC 55 ms
19,184 KB
testcase_48 AC 61 ms
19,136 KB
testcase_49 WA -
testcase_50 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int H,W,N;
int X[202020],Y[202020];

vector<pair<int,int>> E[402020];
vector<pair<int,int>> path;
int vis[404040];

void dfs(int cur,int pre) {
	
	if(vis[cur]) {
		vector<int> ret;
		int ok=0;
		FORR2(e,i,path) {
			if(ok) ret.push_back(i+1);
			if(e==cur) ok++;
		}
		cout<<ret.size()<<endl;
		FORR(r,ret) cout<<r<<" ";
		cout<<endl;
		exit(0);
		
	}
	vis[cur]=1;
	FORR2(e,i,E[cur]) if(e!=pre) {
		path.push_back({e,i});
		dfs(e,cur);
		path.pop_back();
		
	}
	
	
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>N;
	FOR(i,N) {
		cin>>Y[i]>>X[i];
		Y[i]--,X[i]--;
		E[Y[i]].push_back({H+X[i],i});
		E[H+X[i]].push_back({Y[i],i});
	}
	
	FOR(y,H) if(vis[y]==0) {
		path.push_back({y,-1});
		dfs(y,-1);
		path.pop_back();
	}
	
	cout<<-1<<endl;
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0