/*
ID: sifx_xu1
PROG: tour
LANG: C++
*/
#include
<
cstdio
>
#include
<
cstdlib
>
#include
<
cstring
>
using
namespace
std;
int
N,M;
int
e[
101
][
101
]
=
{
0
};
int
f[
101
][
101
];
char
s[
101
][
20
];
int
getnum(
char
*
s1)
{
for
(
int
i
=
1
;i
<=
N;
++
i)
if
(strcmp(s[i],s1)
==
0
)
return
i;
}
void
init()
{
scanf(
"
%d%d
"
,
&
N,
&
M);
for
(
int
i
=
1
;i
<=
N;
++
i)
scanf(
"
%s
"
,s[i]);
for
(
int
i
=
1
;i
<=
M;
++
i){
scanf(
"
%s
"
,s[
0
]);
int
x
=
getnum(s[
0
]);
scanf(
"
%s
"
,s[
0
]);
int
y
=
getnum(s[
0
]);
e[x][y]
=
e[y][x]
=
1
;
}
}
void
DP()
{
int
ans
=
1
;
f[
1
][
1
]
=
1
;
for
(
int
i
=
1
;i
<=
N;
++
i){
for
(
int
j
=
i
+
1
;j
<=
N;
++
j){
f[i][j]
=-
0xFFFFFFF
;
for
(
int
k
=
1
;k
<
j;
++
k)
if
(e[k][j]
&&
f[i][k]
>
0
&&
f[i][k]
+
1
>
f[i][j])
f[i][j]
=
f[j][i]
=
f[i][k]
+
1
;
}
if
(e[i][N]
&&
f[i][N]
>
ans)
ans
=
f[i][N];
}
printf(
"
%d\n
"
,ans);
}
int
main()
{
freopen(
"
tour.in
"
,
"
r
"
,stdin);
freopen(
"
tour.out
"
,
"
w
"
,stdout);
init();
DP();
return
0
;
}
/*
Executing
Test 1: TEST OK [0.011 secs, 2880 KB]
Test 2: TEST OK [0.000 secs, 2880 KB]
Test 3: TEST OK [0.011 secs, 2880 KB]
Test 4: TEST OK [0.011 secs, 2880 KB]
Test 5: TEST OK [0.000 secs, 2880 KB]
Test 6: TEST OK [0.000 secs, 2880 KB]
Test 7: TEST OK [0.000 secs, 2880 KB]
Test 8: TEST OK [0.011 secs, 2880 KB]
Test 9: TEST OK [0.022 secs, 2880 KB]
Test 10: TEST OK [0.011 secs, 2880 KB]
Test 11: TEST OK [0.022 secs, 2880 KB]
*/
posted on 2009-07-20 15:34
xfstart07 阅读(180)
评论(0) 编辑 收藏 引用