Recall that link-state protocols are based on neighbor relationships, so every router within an area knows about all the active links within its area and knows the identity of router-originating information about these active links.
Every router advertises the cost and state of its links. This state information is then propagated one hop away. This propagation of information results in all routers having identical databases. Every router is identified by its unique address, so a loop is avoided.
To reach a destination, the cost is the sum of all the costs of the concerned links to that destination. After the router has received information about all the other routers and their links, each individual router runs an SPF algorithm, ...