比赛 20111012 评测结果 AAAAAAAAAA
题目名称 空中楼阁 最终得分 100
用户昵称 苏轼 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2011-10-12 20:38:24
显示代码纯文本
#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;
}