#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ addEdge(unsigned int *, unsigned int, unsigned int);
int /*<<< orphan*/ free(unsigned int *);
unsigned int getMaxPalindromeLengthOptimised(unsigned int *, unsigned int);
unsigned int getRootNode(unsigned int *, unsigned int);
int /*<<< orphan*/ initializeSet(unsigned int);
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ memset(unsigned int *, int, int);
int /*<<< orphan*/ printf(char *, unsigned int);
int /*<<< orphan*/ scanf(char *, unsigned int *, ...);
int main() {
  unsigned int *arr, *brr, n, k, j, m, i, x, y;
  unsigned int maxPalindromeLength;
  scanf("%u%u%u", &n, &k, &m);
  unsigned int v = n + 1;
  unsigned int *arrLoc = (unsigned int *)malloc(sizeof(unsigned int) * v);
  memset(arrLoc, -1, sizeof(unsigned int) * v);
  initializeSet(v);
  for (j = 0; j < k; j++) {
    scanf("%u%u", &x, &y);
    if (x != y) {
      addEdge(arrLoc, x, y);
    }
  }
  arr = (unsigned int *)malloc(m * sizeof(unsigned int));
  brr = (unsigned int *)malloc(m * sizeof(unsigned int));
  for (i = 0; i < m; i++) {
    scanf("%u", &arr[i]);
  }
  for (i = 0; i < m; i++) {
    brr[i] = getRootNode(arrLoc, arr[i]);
  }
  free(arr);
  free(arrLoc);
  maxPalindromeLength = getMaxPalindromeLengthOptimised(brr, m);
  free(brr);
  printf("%u\n", maxPalindromeLength);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe5a(%rip),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rcx
mov    $0x0,%al
call   10b0 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x3c(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edx
mov    $0xffffffff,%esi
call   1060 <memset@plt>
mov    -0x3c(%rbp),%edi
call   1040 <initializeSet@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jae    124a <main+0xba>
lea    0xdf5(%rip),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
mov    $0x0,%al
call   10b0 <scanf@plt>
mov    -0x30(%rbp),%eax
cmp    -0x34(%rbp),%eax
je     1237 <main+0xa7>
mov    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
call   10a0 <addEdge@plt>
jmp    123c <main+0xac>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11fa <main+0x6a>
mov    -0x28(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jae    12ab <main+0x11b>
mov    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%eax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   10b0 <scanf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1275 <main+0xe5>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jae    12eb <main+0x15b>
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    (%rax,%rcx,4),%esi
call   1070 <getRootNode@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12b2 <main+0x122>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   1080 <getMaxPalindromeLengthOptimised@plt>
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%esi
lea    0xce8(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe5b(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
xor    %eax,%eax
call   10b0 <scanf@plt>
mov    0x14(%rsp),%eax
lea    0x4(,%rax,4),%ebx
mov    %eax,%ebp
add    $0x1,%ebp
mov    %ebx,%edi
call   1090 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    $0xffffffff,%esi
mov    %ebx,%edx
call   1060 <memset@plt>
mov    %ebp,%edi
call   1040 <initializeSet@plt>
cmpl   $0x0,0x8(%rsp)
je     123f <main+0xaf>
lea    0xe09(%rip),%r14
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%rbx
xor    %ebp,%ebp
jmp    1219 <main+0x89>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    0x8(%rsp),%ebp
jae    123f <main+0xaf>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10b0 <scanf@plt>
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
cmp    %edx,%esi
je     1210 <main+0x80>
mov    %r12,%rdi
call   10a0 <addEdge@plt>
jmp    1210 <main+0x80>
mov    0x4(%rsp),%edi
shl    $0x2,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    0x4(%rsp),%edi
shl    $0x2,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
cmpl   $0x0,0x4(%rsp)
je     12bd <main+0x12d>
lea    0xd99(%rip),%r13
mov    %r15,%rbx
xor    %ebp,%ebp
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10b0 <scanf@plt>
add    $0x1,%rbp
mov    0x4(%rsp),%eax
add    $0x4,%rbx
cmp    %rax,%rbp
jb     1270 <main+0xe0>
test   %eax,%eax
je     12bd <main+0x12d>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r15,%rbx,4),%esi
mov    %r12,%rdi
call   1070 <getRootNode@plt>
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
mov    0x4(%rsp),%eax
cmp    %rax,%rbx
jb     12a0 <main+0x110>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x4(%rsp),%esi
mov    %r14,%rdi
call   1080 <getMaxPalindromeLengthOptimised@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xd1d(%rip),%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%u%u%u\00"
@.str.1 = [5 x i8] c"%u%u\00"
@.str.2 = [3 x i8] c"%u\00"
@.str.3 = [4 x i8] c"%u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
store i32 0, i32* %1
%14 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %5, i32* %7)
%15 = load i32, i32* %4
%16 = add i32 %15, 1
store i32 %16, i32* %12
%17 = load i32, i32* %12
%18 = zext i32 %17 to i64
%19 = mul i64 4, %18
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i32*
store i32* %22, i32** %13
%23 = load i32*, i32** %13
%24 = load i32, i32* %12
%25 = zext i32 %24 to i64
%26 = mul i64 4, %25
%27 = trunc i64 %26 to i32
%28 = call i32 @memset(i32* %23, i32 -1, i32 %27)
%29 = load i32, i32* %12
%30 = call i32 @initializeSet(i32 %29)
store i32 0, i32* %6
br label %31
31: ; preds = %46, %0
%32 = load i32, i32* %6
%33 = load i32, i32* %5
%34 = icmp ult i32 %32, %33
br i1 %34, label %35, label %49
35: ; preds = %31
%36 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %9, i32* %10)
%37 = load i32, i32* %9
%38 = load i32, i32* %10
%39 = icmp ne i32 %37, %38
br i1 %39, label %40, label %45
40: ; preds = %35
%41 = load i32*, i32** %13
%42 = load i32, i32* %9
%43 = load i32, i32* %10
%44 = call i32 @addEdge(i32* %41, i32 %42, i32 %43)
br label %45
45: ; preds = %40, %35
br label %46
46: ; preds = %45
%47 = load i32, i32* %6
%48 = add i32 %47, 1
store i32 %48, i32* %6
br label %31
49: ; preds = %31
%50 = load i32, i32* %7
%51 = zext i32 %50 to i64
%52 = mul i64 %51, 4
%53 = trunc i64 %52 to i32
%54 = call i64 @malloc(i32 %53)
%55 = inttoptr i64 %54 to i32*
store i32* %55, i32** %2
%56 = load i32, i32* %7
%57 = zext i32 %56 to i64
%58 = mul i64 %57, 4
%59 = trunc i64 %58 to i32
%60 = call i64 @malloc(i32 %59)
%61 = inttoptr i64 %60 to i32*
store i32* %61, i32** %3
store i32 0, i32* %8
br label %62
62: ; preds = %72, %49
%63 = load i32, i32* %8
%64 = load i32, i32* %7
%65 = icmp ult i32 %63, %64
br i1 %65, label %66, label %75
66: ; preds = %62
%67 = load i32*, i32** %2
%68 = load i32, i32* %8
%69 = zext i32 %68 to i64
%70 = getelementptr inbounds i32, i32* %67, i64 %69
%71 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %70)
br label %72
72: ; preds = %66
%73 = load i32, i32* %8
%74 = add i32 %73, 1
store i32 %74, i32* %8
br label %62
75: ; preds = %62
store i32 0, i32* %8
br label %76
76: ; preds = %92, %75
%77 = load i32, i32* %8
%78 = load i32, i32* %7
%79 = icmp ult i32 %77, %78
br i1 %79, label %80, label %95
80: ; preds = %76
%81 = load i32*, i32** %13
%82 = load i32*, i32** %2
%83 = load i32, i32* %8
%84 = zext i32 %83 to i64
%85 = getelementptr inbounds i32, i32* %82, i64 %84
%86 = load i32, i32* %85
%87 = call i32 @getRootNode(i32* %81, i32 %86)
%88 = load i32*, i32** %3
%89 = load i32, i32* %8
%90 = zext i32 %89 to i64
%91 = getelementptr inbounds i32, i32* %88, i64 %90
store i32 %87, i32* %91
br label %92
92: ; preds = %80
%93 = load i32, i32* %8
%94 = add i32 %93, 1
store i32 %94, i32* %8
br label %76
95: ; preds = %76
%96 = load i32*, i32** %2
%97 = call i32 @free(i32* %96)
%98 = load i32*, i32** %13
%99 = call i32 @free(i32* %98)
%100 = load i32*, i32** %3
%101 = load i32, i32* %7
%102 = call i32 @getMaxPalindromeLengthOptimised(i32* %100, i32 %101)
store i32 %102, i32* %11
%103 = load i32*, i32** %3
%104 = call i32 @free(i32* %103)
%105 = load i32, i32* %11
%106 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %105)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"%u%u%u\00"
@.str.1 = [5 x i8] c"%u%u\00"
@.str.2 = [3 x i8] c"%u\00"
@.str.3 = [4 x i8] c"%u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %1 to i8*
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2, i32* %3)
%12 = load i32, i32* %1
%13 = add i32 %12, 1
%14 = shl i32 %13, 2
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i32*
%17 = call i32 @memset(i32* %16, i32 -1, i32 %14)
%18 = call i32 @initializeSet(i32 %13)
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, 0
br i1 %20, label %33, label %21
21: ; preds = %0, %29
%22 = phi i32 [ %30, %29 ], [ 0, %0 ]
%23 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32* %5)
%24 = load i32, i32* %4
%25 = load i32, i32* %5
%26 = icmp eq i32 %24, %25
br i1 %26, label %29, label %27
27: ; preds = %21
%28 = call i32 @addEdge(i32* %16, i32 %24, i32 %25)
br label %29
29: ; preds = %21, %27
%30 = add nuw i32 %22, 1
%31 = load i32, i32* %2
%32 = icmp ult i32 %30, %31
br i1 %32, label %21, label %33
33: ; preds = %29, %0
%34 = load i32, i32* %3
%35 = shl i32 %34, 2
%36 = call i64 @malloc(i32 %35)
%37 = inttoptr i64 %36 to i32*
%38 = load i32, i32* %3
%39 = shl i32 %38, 2
%40 = call i64 @malloc(i32 %39)
%41 = inttoptr i64 %40 to i32*
%42 = load i32, i32* %3
%43 = icmp eq i32 %42, 0
br i1 %43, label %64, label %46
44: ; preds = %46
%45 = icmp eq i32 %51, 0
br i1 %45, label %64, label %54
46: ; preds = %33, %46
%47 = phi i64 [ %50, %46 ], [ 0, %33 ]
%48 = getelementptr inbounds i32, i32* %37, i64 %47
%49 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %48)
%50 = add nuw nsw i64 %47, 1
%51 = load i32, i32* %3
%52 = zext i32 %51 to i64
%53 = icmp ult i64 %50, %52
br i1 %53, label %46, label %44
54: ; preds = %44, %54
%55 = phi i64 [ %60, %54 ], [ 0, %44 ]
%56 = getelementptr inbounds i32, i32* %37, i64 %55
%57 = load i32, i32* %56
%58 = call i32 @getRootNode(i32* %16, i32 %57)
%59 = getelementptr inbounds i32, i32* %41, i64 %55
store i32 %58, i32* %59
%60 = add nuw nsw i64 %55, 1
%61 = load i32, i32* %3
%62 = zext i32 %61 to i64
%63 = icmp ult i64 %60, %62
br i1 %63, label %54, label %64
64: ; preds = %54, %33, %44
%65 = call i32 @free(i32* %37)
%66 = call i32 @free(i32* %16)
%67 = load i32, i32* %3
%68 = call i32 @getMaxPalindromeLengthOptimised(i32* %41, i32 %67)
%69 = call i32 @free(i32* %41)
%70 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %68)
ret i32 0
}