結果

問題 No.1647 Travel in Mitaru city 2
ユーザー inksamuraiinksamurai
提出日時 2021-08-13 23:00:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,676 bytes
コンパイル時間 1,247 ms
コンパイル使用メモリ 122,512 KB
実行使用メモリ 30,344 KB
最終ジャッジ日時 2024-04-14 19:56:21
合計ジャッジ時間 13,177 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,940 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 2 ms
6,940 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 120 ms
30,172 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <functional>
#include <numeric>
#include <iomanip> 
#include <stdio.h>
#include <assert.h>
#include <cstring>
//eolibraries
#define lnf 3999999999999999999
#define inf 999999999
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define pii pair <int,int>
#define rep(i,n) for(int i = 0 ; i < n ; i++) 
#define drep(i,n) for(int i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(int i = x ; i < n ; i++)
#define vi vector <int> 
#define vec(...) vector<__VA_ARGS__>
#define _3yHSMG9 ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//eodefine
using namespace std;

const int mxn=12000;

int main(){
_3yHSMG9;
	int h,w,n;
	cin>>h>>w>>n;
	std::map<pii,int> mp;
	vi cntx(h,0),cnty(w,0);
	vec(set<int>) stx(h),sty(w);
	vec(pii) a(n);
	rep(i,n){
		int x,y;
		cin>>x>>y;
		x--,y--;
		a[i]={x,y};
		mp[a[i]]=i;
		stx[x].insert(i);
		sty[y].insert(i);
		cntx[x]++;
		cnty[y]++;
	}
	bool pok=1;
	pii ned={-1,-1};
	rep(i,h){
		if(cntx[i]%2){
			if(ned.fi==-1) ned.fi=i;
			else pok=0;
		}
	}
	rep(i,w){
		if(cnty[i]%2){
			if(ned.se==-1) ned.se=i;
			else pok=0;
		}
	}
	if(!pok){
		cout<<"-1\n";
		exit(0);
	}
	vi walk;
	
	auto dfs=[&](auto self,int id,int t)->void{
		// cout<<id<<" "<<t<<"\n";
		walk.pb(id);
		stx[a[id].fi].erase(stx[a[id].fi].find(id));
		sty[a[id].se].erase(sty[a[id].se].find(id));
		if(t==0){
			if(sz(sty[a[id].se])){
				self(self,*(sty[a[id].se].begin()),1);
			}
		}else{
			if(sz(stx[a[id].fi])){
				self(self,*(stx[a[id].fi].begin()),0);
			}
		}
	};

	if(ned.fi!=-1 and ned.fi!=-1){
		if(!mp[ned]){
			cout<<"-1\n";
			exit(0);
		}else{
			dfs(dfs,mp[ned],0);
		}
	}else{
		if(ned.fi!=-1){
			dfs(dfs,*(stx[ned.fi].begin()),0);
		}else if(ned.se!=-1){
			dfs(dfs,*(sty[ned.se].begin()),0);
		}else{
			rep(i,h){
				if(sz(stx[i])){
					dfs(dfs,*(stx[i].begin()),0);
					break;
				}
			}
		}
	}
	if(sz(walk)<4){
		cout<<"-1\n";
		exit(0);
	}
	if(sz(walk)%2==0){
		if(a[walk.back()].fi!=a[walk[0]].fi){
			cout<<"-1\n";
			exit(0);
		}
	}else{
		if(a[walk.back()].se!=a[walk[0]].se){
			cout<<"-1\n";
			exit(0);
		}
	}
	rep(i,sz(walk)){
		cout<<walk[i]+1;
		if(i<sz(walk)-1)cout<<" ";
	}
	// for(auto x : walk) cout<<x+1<<" ";
	cout<<"\n";
//	
	return 0;
}
0