Q:

How to update contact owner value

I have this SOQL:
SELECT Id, mudouProprietario__c,(SELECT Id, AccountId, OwnerId  FROM Contacts) FROM Account

I need get value of owner account and set the value at the contact owner
I created a for passing the list that returns the select
        Task[] listaTarefaUpdate = new Task[] {};
        Opportunity[] listaOportunidadeUpdate = new Opportunity[] {};
        Contact[] listaContatosUpdate = new Contact[] {};

        Account[] listaContas = (Account[]) scope;

        for( Account contas : listaContas){

            for(Task task: contas.Tasks){

                task.OwnerId = contas.OwnerId; 
                listaTarefaUpdate.add(task);
            }

            for(Opportunity oportunidade : contas.Opportunities){

                oportunidade.OwnerId = contas.OwnerId;
                listaOportunidadeUpdate.add(oportunidade);
            }   

            for(Contact contato : contas.Contacts){

                contato.OwnerId = contas.OwnerId;
                listaContatosUpdate.add(contato);
            }

            contas.mudouProprietario__c = false;

        }

        Database.SaveResult[] srListOpt = Database.update(listaOportunidadeUpdate, false);
        Database.SaveResult[] srListCont = Database.update(listaContatosUpdate, false);
        Database.SaveResult[] srListTar = Database.update(listaTarefaUpdate, false);

It would be like this?

A:

It would be far simpler to approach this from the opposite direction; query the contacts and the account owner in a child-parent relationship instead of a parent-child relationship:
Contact[] records = [SELECT Account.OwnerId FROM Contact WHERE AccountId <> NULL];
for(Contact record: records) {
  record.OwnerId = record.Account.OwnerId;
}
update records;

For many different children, then you might do something like this:
Account[] records = [SELECT OwnerId, (SELECT Id FROM Contacts), (SELECT Id FROM Opportunities WHERE IsClosed = false) FROM Account];
sObject[] updates = new sObject[0];
for(Account record: records) {
  for(Contact contactRecord: record.Contacts) {
    updates.add(new Contact(Id=contactRecord.Id, OwnerId=record.Id));
  }
}
update updates;
updates.clear();
for(Account record: records) {
  for(Opportunity opportunityRecord: record.Opportunities) {
    updates.add(new Opportunity(Id=opportunityRecord.Id, OwnerId=record.Id));
  }
}
update updates;
...

This isn't the only way to do so, but one of several different possibilities.

