(Optional) Introduction to Functional Graphs
Authors: Siyong Huang, Benjamin Qi, Andrew Wang
Prerequisites
Directed graphs in which every vertex has exactly one outgoing edge.
Focus Problem – read through this problem before continuing!
It's easy to solve the above problem in time. We'll solve it in .
Introduction
In a functional graph, each node has exactly one out-edge. This is also commonly referred to as a successor graph.
Resources | |||
---|---|---|---|
CPH | diagrams |
You can think of every connected component of a functional graph as a rooted tree plus an additional edge going out of the root.
Solution - Badge
This section is not complete.
C++
const int MN = 1e3+10;int N, p[MN], f[MN];bool v[MN], u[MN];int dfs(int n){v[n]=u[n]=true;if(u[p[n]])//Cycle created{f[n]=n;//Nodes in cycle point to themselves
Java
import java.io.*;import java.util.*;public class badge{static InputReader in = new InputReader(System.in);static PrintWriter out = new PrintWriter(System.out);public static final int MN = 1010;public static int N;public static int[] p = new int[MN], f = new int[MN];
Floyd's Algorithm
Floyd's Algorithm, also commonly referred to as the Tortoise and Hare Algorithm, is capable of detecting cycles in a functional graph in time and memory (not counting the graph itself).
Resources | |||
---|---|---|---|
CPH | |||
Medium |
Example - Cooperative Game
Focus Problem – read through this problem before continuing!
Hint 1
Hint 2
Solution
Solution
-th Successor
As described briefly in CPH 16.3, can be found in time using binary jumping. See the Platinum module for details.
Problems
Status | Source | Problem Name | Difficulty | Tags | Solution |
---|---|---|---|---|---|
Silver | Easy | Show TagsFunc Graph | External Sol | ||
CSES | Normal | Show TagsFunc Graph | View Solution | ||
Silver | Normal | Show TagsPermutation | External Sol |
Additional problems involving functional graphs can be found in the Tree DP and Binary Jumping modules.