USACO Silver 2014 December - Piggy Back

Authors: Qi Wang, Kakulavaram Sanjana Reddy


Official Analysis

Time Complexity: O(N)\mathcal{O}(N)

C++

#include <bits/stdc++.h>
using namespace std;
unordered_map<int, vector<int>> mp;
vector<vector<int>> dist;
// Function to find distance from node s to node ix
void distance(int s, int ix) {
// Declare a queue to store the node and its distance from start node as a
// pair

Java

Java Implementation

import java.io.*;
import java.util.*;
public class PiggyBack {
static int B, E, P, N, M, A = Integer.MAX_VALUE;
static List<Integer>[] adj;
static int[][] dist;
public static void main(String[] args) throws Exception {
Kattio io = new Kattio("piggyback");

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!