USACO Gold 2020 February - Timeline

Authors: Sofia Yang, Jeffrey Zhang

Table of Contents

SolutionImplementation

Solution

Official Analysis

Implementation

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

C++

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
void topo_sorting(vector<vector<pair<int, int>>> &graph, vector<bool> &visited,
vector<int> &toposort, int node) {
visited[node] = true;
for (auto i : graph[node]) {
int a, b;
tie(a, b) = i;

Java

import java.io.*;
import java.util.*;
public class timeline {
public static void main(String[] args) throws IOException {
BufferedReader r = new BufferedReader(new FileReader("timeline.in"));
PrintWriter pw = new PrintWriter("timeline.out");
StringTokenizer st = new StringTokenizer(r.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());

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!