Implementation
Time Complexity: , where denotes the maximum height difference between any two cells
Java
import java.io.*;import java.util.*;public class CrossCountrySkiing {static int n, m;static int startI, startJ; // Stores starting position of each floodfillstatic int[][] course; // Stores the skiing course heightsstatic boolean[][] waypoints; // Stored as booleans instead of 1s and 0sstatic boolean[][] vis; // Visited array for floodfill
C++
#include <bits/stdc++.h>using namespace std;const int dy[] = {-1, 0, 1, 0};const int dx[] = {0, -1, 0, 1};constexpr int MAX_N = 500;int m, n;int wy, wx;
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!