program main integer*8::N,M,K,i,j,l,src,dest integer*8,allocatable::road(:,:) integer*8,allocatable::list(:,:,:) integer*8,allocatable::keiro(:) integer*8,allocatable::han1(:),han2(:) integer*8::ryoukin, num, tmp read *,N,M,K allocate(road(3,M)) allocate(list(2,N,0:N)) allocate(keiro(K)) allocate(han1(N)) allocate(han2(N)) read *, road read *, keiro han1 = 1 han2 = 0 list = 0 do i=1,N src = road(1,i) dest = road(2,i) ryoukin = road(3,i) list(1, src, 0) = list(1, src, 0) + 1 list(1, src, list(1, src, 0)) = dest list(1, dest, 0) = list(1, dest, 0) + 1 list(1, dest, list(1, dest, 0)) = src list(2, src, list(1, src, 0)) = ryoukin list(2,dest, list(1, dest, 0)) = ryoukin end do do i=1, K ryoukin = keiro(i) do j=1, N if(han1(j).eq.1) then tmp = list(1,j,0) do l=1, tmp if(list(2,j,l).eq.ryoukin) then han2(list(1,j,l)) = 1 end if end do end if end do han1 = han2 han2 = 0 end do num = SUM(han1) print '(i0)', num do i=1,N if(han1(i).eq.1) then num = num - 1 if(num.ne.0) then write(6,'(i0,a)',advance='no') i, " " else write(6,'(i0)') i end if end if end do end program main