Kai nodded slowly. "You are looking for a direct path back to the winner. But what if the path is three steps? Four? Your recursion only goes two levels deep."
// Returns true if adding edge winner->loser creates a cycle bool creates_cycle(int winner, int loser) { // If the loser can reach the winner through existing locked edges, // then adding winner->loser would complete a cycle. return dfs(loser, winner); } bool dfs(int current, int target) { if (current == target) return true; for (int i = 0; i < candidate_count; i++) { if (locked[current][i] && dfs(i, target)) return true; } return false; }
"Show me your cycle detection," Kai said.
Her friend, an old sysadmin named Kai, peered over her shoulder. "You're trying to lock every pair in order of strength, right?"
Kai chuckled. "That's not just Tideman, Maya. That's life. Don't create cycles. Always check if the person you're stepping on has a hidden path back to you."
от 6 декабря 2025 года появились изменения в правилах
1. В основных правилах изменился пункт 4.26 Cs50 Tideman Solution
2. в правилах гаранта изменения в пункте 6.1 Kai nodded slowly
Если вы не согласны с изменениями вы должны прекратить использование форума. Her friend, an old sysadmin named Kai, peered