結果
| 問題 |
No.1647 Travel in Mitaru city 2
|
| コンテスト | |
| ユーザー |
inksamurai
|
| 提出日時 | 2021-08-13 23:00:02 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,676 bytes |
| コンパイル時間 | 1,752 ms |
| コンパイル使用メモリ | 124,908 KB |
| 実行使用メモリ | 30,124 KB |
| 最終ジャッジ日時 | 2024-10-03 22:11:41 |
| 合計ジャッジ時間 | 12,777 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | AC * 2 WA * 46 |
ソースコード
#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;
}
inksamurai