Q:

Didn't understand the relationship AccountLocations__r

I have got two objects Account and AccountLocation__c with a master-detail relationship where AccountLocation__c.Account__c references Account.ID. Manual check does confirm the relationship.
The parent to child query:
SELECT Account.ID, (SELECT Account__c FROM Account.AccountLocations__r) FROM Account

returns the rows while the child to parent query:
SELECT Account__c, AccountLocations__r.Account.ID FROM AccountLocation__c

results in the error 
Didn't understand relationship 'AccountLocations__r' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.

Another question is that the second query returns of the form 
ID, AccountLocations__r[{"Account__c":id1}, {"Account__c":id2}]

Considering the cardinalities, how can I extract only the IDs here?

A:

There's really no need to use table names in your query (e.g. select account.id from account), but if you are insisting on using them, then your second query probably should have been:
SELECT Account__c, AccountLocations__c.Account__r.ID FROM AccountLocation__c

Use __r only to refer to a relationship. The table name doesn't change to __r. This is one reason I tend to avoid table names/aliases in straight queries, because it complicates otherwise easy code.
As a side note, Account__c and Account__r.Id refer to the same value. You really wouldn't normally refer to both of them that way.
The second query wouldn't return that form, although the first would (I presume this what you meant). Extracting the values can be done several ways. One possible way to get just Id values could look like:
Set<Id> ids = new Map<Id, AccountLocation__c>(results[0].AccountLocation__r).keySet();

However, depending on your use case, you might not even need to do that. You can bind an SObject list to a query variable, for example, and the query returns all values that match the IDs in the list.
You could also do this a bit more manually and just loop through the values and add them to a list or set.

