USACO Silver 2019 February - The Great Revegetation
Authors: Sofia Yang, Ryan Chou, Jay Fu
Explanation
Assume that we have a valid solution composed of connected components in our graph.
Let's look at one of these connected components, which could look something like this:
However, for each of the connected components, the grass types can be inverted and still be a valid solution:
There are possible ways to arrange each connected component. Thus, if there's connected components, there's ways to arrange the entire graph.
Note how the nodes force their adjacent ones to have a specific coloring, so if any two nodes don't satisfy this condition, it's impossible. Otherwise, the solution will always be .
Implementation
C++
#include <bits/stdc++.h>using namespace std;int main() {freopen("revegetate.in", "r", stdin);freopen("revegetate.out", "w", stdout);int n, m;cin >> n >> m;
Java
import java.io.*;import java.util.ArrayList;import java.util.StringTokenizer;public class Revegetate {public static int[] type;public static boolean impossible;public static ArrayList<Integer>[] same;public static ArrayList<Integer>[] diff;
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!