Technically there is no such thing as a bitcoin. Just unspent transaction outputs. Those get spent as an input of a transaction and then are gone forever. There is no concept of the output of a transaction being the same "bitcoin" as what comes from the input of the transaction. This means if you had 2 inputs and 2 outputs of the same amount there is no way to trace which input became which output. At best you can find which outputs potentially came from an input.
That is called tracing. It’s also not hard - every node does it to verify blocks.