USACO Silver 2019 December - Milk Visits

Author: Qi Wang

Official Analysis

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

C++

//Official Solution modified by Qi Wang
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)

Java

//Created by Qi Wang
import java.util.*;
import java.io.*;
public class milkvisit {
static int N, M, num=1;
static boolean[] col;
static int[] comp;
static List<Integer>[] adj;

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!