module graph_mod
    use,intrinsic :: iso_fortran_env
    implicit none
    type node
        integer(int32),allocatable:: to(:)
        integer(int32):: l
    contains
        procedure::  init => node_init
        procedure:: regist => node_regist
    end type


    type graph
        type(node),allocatable:: n(:)
    contains
        procedure:: regist => graph_regist
        procedure:: l => graph_elem_num
        procedure:: v => graph_elem_val
    end type
    interface graph
        module procedure graph_init
    end interface
    private
    public:: graph
contains
    function graph_init(n) result(g)
        type(graph):: g
        integer(int32),intent(in):: n
        integer(int32):: i

        allocate(g%n(n))
        do i=1,n
            call g%n(i)%init()
        end do
    end function


    subroutine graph_regist(g,x,y)
        class(graph):: g
        integer(int32):: x,y

        call g%n(x)%regist(y)
        call g%n(y)%regist(x)
    end subroutine


    function graph_elem_num(g,i) result(ret)
        class(graph):: g
        integer(int32):: i,ret

        ret = g%n(i)%l
    end function


    function graph_elem_val(g,i,j) result(ret)
        class(graph):: g
        integer(int32):: i,j,ret

        ret = g%n(i)%to(j)
    end function


    subroutine node_init(n)
        class(node):: n
        allocate(n%to(1))

        n%l = 0
    end subroutine


    subroutine node_regist(n,m)
        class(node):: n
        integer(int32):: m

        if (n%l+1 > size(n%to)) call add_(n)
        n%l=n%l+1
        n%to(n%l) = m
    end subroutine


    subroutine add_(n)
        type(node):: n
        integer(int32),allocatable:: tmp(:)
        integer(int32):: l

        l = size(n%to)
        allocate(tmp(l))
        tmp(:) = n%to(:)
        deallocate(n%to)
        allocate(n%to(l*2))
        n%to(1:l) = tmp(:)
        deallocate(tmp)
    end subroutine
end module

program abc157_d
    use,intrinsic :: iso_fortran_env
    use graph_mod
    implicit none
    type(graph):: frd
    integer(int32):: n,m,k
    integer(int32):: i,j
    integer(int32), allocatable:: ans(:), affiliation_of(:), num_team_of(:)

    read*, n,m,k
    frd = graph(n)
    do i=1,m
        block; integer(int32):: a,b
            read*, a,b
            call frd%regist(a,b)
        end block
    end do

    allocate(ans(n))
    allocate(affiliation_of(n), source=0)
    allocate(num_team_of(n),source=-1)

    j=0
    do i=1,n
        if (affiliation_of(i) > 0) cycle
        j=j+1
        block
            integer(int32):: cn
            cn = trace_back_friend(i, j)
            num_team_of(j) = cn
        end block
    end do

    do i=1,n
        ans(i) = num_team_of(affiliation_of(i)) - frd%l(i) - 1
    end do
        
    do i=1,k
        block; integer(int32):: c,d
            read*, c,d
            if (affiliation_of(c) == affiliation_of(d)) then
                ans(c)=ans(c)-1
                ans(d)=ans(d)-1
            end if
        end block
    end do
    print'(*(i0,1x))', ans(:)
contains
    recursive function trace_back_friend(self, n) result(ret)
        integer(int32):: self, n, ret, i, to
        
        affiliation_of(self) = n
        ret = 1
        do i=1,frd%l(self)
            to = frd%v(self,i)
            if (affiliation_of(to) > 0) cycle
            ret=ret+trace_back_friend(to, n)
        end do
    end function
end program abc157_d

Measured memory_bytes: 17212