记录编号 |
28826 |
评测结果 |
AAAAAAAAAA |
题目名称 |
空中楼阁 |
最终得分 |
100 |
用户昵称 |
苏轼 |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.077 s |
提交时间 |
2011-10-17 19:49:59 |
内存使用 |
0.29 MiB |
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
bool map[11][81][81], boo[81];
unsigned dist[81];
int main ()
{
freopen("house.in", "r", stdin);
freopen("house.out", "w", stdout);
int n, m, t;
scanf("%d%d%d", &n, &m, &t);
memset(dist, 0xFF, (n+1)*sizeof(unsigned));
for (int i=1; i<=t; i++)
for (int j=0; j<m; j++)
{
int a, b;
scanf("%d%d", &a, &b);
map[i%t][a][b] = map[i%t][b][a] = true;
}
queue<int> q;
dist[1] = 1;
boo[1] = true;
q.push(1);
while (q.size())
{
int curr = q.front();
boo[curr] = false;
q.pop();
int type = dist[curr] % t;
for (int i=0; i<=n; i++)
if (i != curr)
for (int j=type; j<type+t; j++)
if (map[j%t][curr][i] &&
dist[curr]+j-type+1 < dist[i])
{
dist[i] = dist[curr] + j - type + 1;
if (!boo[i])
{
boo[i] = true;
q.push(i);
}
}
}
if (dist[0] < 0xFFFFFFFF)
printf("%u\n", dist[0]-1);
else
printf("Poor Z4!\n");
return 0;
}