結果

問題 No.1647 Travel in Mitaru city 2
ユーザー 👑 kmjpkmjp
提出日時 2021-08-13 23:11:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,500 ms
コード長 1,624 bytes
コンパイル時間 2,081 ms
コンパイル使用メモリ 201,808 KB
実行使用メモリ 28,552 KB
最終ジャッジ日時 2024-04-21 04:56:31
合計ジャッジ時間 8,141 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
13,056 KB
testcase_01 AC 5 ms
13,056 KB
testcase_02 AC 5 ms
12,800 KB
testcase_03 AC 5 ms
13,056 KB
testcase_04 AC 6 ms
12,928 KB
testcase_05 AC 5 ms
12,928 KB
testcase_06 AC 5 ms
13,056 KB
testcase_07 AC 7 ms
13,056 KB
testcase_08 AC 68 ms
26,960 KB
testcase_09 AC 64 ms
24,788 KB
testcase_10 AC 79 ms
27,108 KB
testcase_11 AC 55 ms
21,564 KB
testcase_12 AC 57 ms
21,044 KB
testcase_13 AC 59 ms
22,248 KB
testcase_14 AC 72 ms
27,484 KB
testcase_15 AC 70 ms
27,164 KB
testcase_16 AC 67 ms
26,148 KB
testcase_17 AC 55 ms
22,496 KB
testcase_18 AC 60 ms
21,456 KB
testcase_19 AC 67 ms
26,616 KB
testcase_20 AC 67 ms
24,712 KB
testcase_21 AC 78 ms
27,248 KB
testcase_22 AC 70 ms
27,560 KB
testcase_23 AC 71 ms
27,656 KB
testcase_24 AC 66 ms
25,092 KB
testcase_25 AC 72 ms
26,380 KB
testcase_26 AC 74 ms
27,916 KB
testcase_27 AC 74 ms
28,012 KB
testcase_28 AC 75 ms
28,428 KB
testcase_29 AC 74 ms
28,552 KB
testcase_30 AC 75 ms
26,888 KB
testcase_31 AC 74 ms
28,552 KB
testcase_32 AC 66 ms
27,792 KB
testcase_33 AC 68 ms
25,480 KB
testcase_34 AC 75 ms
28,432 KB
testcase_35 AC 70 ms
26,124 KB
testcase_36 AC 77 ms
28,552 KB
testcase_37 AC 75 ms
28,552 KB
testcase_38 AC 66 ms
24,316 KB
testcase_39 AC 60 ms
22,296 KB
testcase_40 AC 65 ms
24,196 KB
testcase_41 AC 63 ms
22,572 KB
testcase_42 AC 71 ms
24,324 KB
testcase_43 AC 7 ms
13,056 KB
testcase_44 AC 7 ms
13,056 KB
testcase_45 AC 52 ms
18,816 KB
testcase_46 AC 61 ms
18,560 KB
testcase_47 AC 55 ms
18,816 KB
testcase_48 AC 57 ms
18,560 KB
testcase_49 AC 51 ms
18,688 KB
testcase_50 AC 51 ms
18,816 KB
権限があれば一括ダウンロードができます

ソースコード

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++;
		}
		if(cur>=H) {
			reverse(ret.begin(),ret.end()-1);
		}
		
		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