20240508

I bought my first curved monitor, which cost over $200 (!). So far, my experience with it has been great. High resolution. Unique experience.

Today was a busy day. I feel a bit tired.

1969A. Two Friends

At first glance, Topological sort comes to my mind but its difficulty is 800, and I doubt I need to implement an algorithm with Topological sort.

It turned out it's just an implementation problem, as

note that the pi-th friend doesn't have to actually come to the party

package main

import (
    "bufio"
    "fmt"
    "os"
    "strconv"
    "strings"
)

func minInvitation(n int, p []int) int {
    for i := 0; i < n; i++ {
        if i == p[p[i]-1]-1 {
            return 2
        }
    }
    return 3
}

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan()
    t, _ := strconv.Atoi(scanner.Text())

    for tc := 0; tc < t; tc++ {
        scanner.Scan()
        n, _ := strconv.Atoi(scanner.Text())
        var p []int = make([]int, n)
        scanner.Scan()
        for i, piStr := range strings.Split(scanner.Text(), " ") {
            p[i], _ = strconv.Atoi(piStr)
        }
        fmt.Println(minInvitation(n, p))
    }
}

This problem reminds me that I was not the best friend of my best friends.


Avocado rolls 300 Sushi bowl 600 Chips 500 Yogurt 100 Bubble tea 600

Total 2100 kcal


index 20240507 20240509