Drazil created a following problem about putting 1 × 2 tiles into an n × m grid:

"There is a grid with some cells that are empty and some cells that are occupied. You should use 1 × 2 tiles to cover all empty cells and no two tiles should cover each other. And you should print a solution about how to do it."

But Drazil doesn't like to write special checking program for this task. His friend, Varda advised him: "how about asking contestant only to print the solution when it exists and it is unique? Otherwise contestant may print 'Not unique' ".

Drazil found that the constraints for this task may be much larger than for the original task!

Can you solve this new problem?

Note that you should print 'Not unique' either when there exists no solution or when there exists several different solutions for the original task.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 2000).

The following n lines describe the grid rows. Character '.' denotes an empty cell, and the character '*' denotes a cell that is occupied.

Output

If there is no solution or the solution is not unique, you should print the string "Not unique".

Otherwise you should print how to cover all empty cells with 1 × 2 tiles. Use characters "<>" to denote horizontal tiles and characters "^v" to denote vertical tiles. Refer to the sample test for the output format example.

Examples

Input
3 3
...
.*.
...
Output
Not unique
Input
4 4
..**
*...
*.**
....
Output
<>**
*^<>
*v**
<><>
Input
2 4
*..*
....
Output
*<>*
<><>
Input
1 1
.
Output
Not unique
Input
1 1
*
Output
*

Note

In the first case, there are indeed two solutions:

<>^
^*v
v<>

and

^<>
v*^
<>v

so the answer is "Not unique".

题意:输入一个n*m包括'*'和'.'的矩阵,'.'表示该位置为空。'*'表示该位置已有东西。用一个1*2的瓷砖去填满空位置,如果只有一种方法,输出该方法。如果无解或有2种以上的方法输出Not unique.

题解:类似于拓扑排序的想法,将四周只有一个 ' . ' 的点放进队列,之后跑完队列里面所有的点就可以了,在跑的时候,确定另一块砖的时候要将其四周的点的b数组更新,之后队列为空后验证是否可以将所有的地都铺满

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<stack>
#include<map>
#include<cstdlib>
#include<vector>
#include<string>
#include<queue>
using namespace std; #define ll long long
#define llu unsigned long long
#define INF 0x3f3f3f3f
const double PI = acos(-1.0);
const int maxn = 2e3+;
const int mod = 1e9+; int dx[] = {,,,-};
int dy[] = {,-,,};
int n,m;
char a[maxn][maxn];
int b[maxn][maxn];
struct Node {
int x,y;
};
queue<Node>que;
int Count(int x,int y) //计算每一个点的四周的.的数量
{
int ans = ;
for(int i=;i<;i++)
{
int xx = x + dx[i];
int yy = y + dy[i];
if(xx>= && xx<n && yy>= && yy<m && a[xx][yy]=='.')
ans++;
}
return ans;
}
void update(int x,int y) //重新数四周只有一个.的点放进队列
{
for(int i=;i<;i++)
{
int xx = x + dx[i];
int yy = y + dy[i];
if(xx>= && xx<n && yy>= && yy<m && a[xx][yy]=='.')
{
b[xx][yy]=Count(xx,yy);
if(b[xx][yy] == )
que.push(Node{xx,yy});
}
}
}
bool check() //判断是否可以将全部的.都填满
{
for(int i=;i<n;i++)
for(int j=;j<m;j++)
if(a[i][j] == '.')
return false;
return true;
}
int main()
{ scanf("%d%d",&n,&m);
for(int i=;i<n;i++)
scanf("%s",a[i]);
Node node;
memset(b,,sizeof b);
while(!que.empty())
que.pop();
for(int i=;i<n;i++) //将四周只有一个.的放进队列
{
for(int j=;j<m;j++)
{
if(a[i][j] == '*')
continue;
b[i][j] = Count(i,j);
if(b[i][j] == )
{
node.x = i;
node.y = j;
que.push(node);
}
}
}
while(!que.empty()) //类拓扑
{
node = que.front();
que.pop();
int x = node.x;
int y = node.y;
for (int i = ; i < ; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx >= && nx < n && ny >= && ny < m && a[nx][ny] == '.') {
if (i == ) {
a[x][y] = '<';
a[nx][ny] = '>';
} else if (i == ) {
a[x][y] = '>';
a[nx][ny] = '<';
} else if (i == ) {
a[x][y] = '^';
a[nx][ny] = 'v';
} else if (i == ) {
a[x][y] = 'v';
a[nx][ny] = '^';
}
update(x, y);
update(nx, ny);
break;
}
}
}
if(check())
{
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
printf("%c",a[i][j]);
}
printf("\n");
}
}
else
puts("Not unique"); }

最新文章

  1. JAVA编程讲座-吴老
  2. 轻量级富文本编辑器wangEditor源码结构介绍
  3. 用.Net Mage工具更新WPF ClickOnce应用程序部署清单
  4. paip.获取地理位置根据Ip
  5. WPF DataGrid的分页实现
  6. (转) java 简单工厂模式(实现一个计算器)
  7. Ubuntu14.04LTS安装记录(办公室联想台式机)
  8. mongodb 3.x WiredTiger存储优化测试
  9. JQuery图片滑动插件
  10. 数位DP入门Ural1057
  11. /etc/security/limits.conf 设置
  12. STL的一些泛型算法
  13. Objective-C 2.0属性(Property)介绍
  14. Python3基础 内嵌函数 简单示例
  15. 【转载】Windows Server 2012服务器删除IIS方法
  16. Mac_IntelliJ IDEA For Mac 快捷键
  17. Ubuntu安装设置nginx和nohup常用操作
  18. Codeforces 374D - Inna and Sequence
  19. Java输入输出流详解2
  20. RESTful API &amp; Swagger入门

热门文章

  1. Hibernate课程 初探多对多映射2-3 配置映射文件
  2. javascript中如何实现继承
  3. switch 和 if...else if 的区别
  4. SharePoint 2010 网络上的开发经验和资源
  5. nvd3基于时间轴流程图
  6. 调试wmi连接主机进行监控
  7. Android(java)学习笔记97:使用GridView以及重写BaseAdapter
  8. 模拟猜数(POJ2328)
  9. Rich feature hierarchies for accurate object detection and semantic segmentation(RCNN)
  10. webpack-dev-middleware插件的使用