You were given the UK visa the 2nd time…so you don’t need to answer "NO"……but with IRCC better to provide details and be honest.
IMM5669 - Schedule A form……answer “YES” to;
Q4.d) been refused refugee status, an immigrant or permanent resident visa (including a Certificat de sélection du Québec (CSQ) or application to the Provincial Nominee Program ) or visitor or temporary resident visa, to Canada or any other country?
IMM5669 - Schedule A form….. “If your answer to any of the questions is YES, please provide details below”......in this section;
Provide details that your 1st UK visa application was refused but re-applied and your 2nd UK visa application was approved.