Problem Set 7: Network Flows Fall 2018

Similar documents
Southeastern European Regional Programming Contest Bucharest, Romania Vinnytsya, Ukraine October 21, Problem A Concerts

ACM ICPC World Finals Warmup 2 At UVa Online Judge. 7 th May 2011 You get 14 Pages 10 Problems & 300 Minutes

ProCo 2017 Advanced Division Round 1

MATHEMATICS ON THE CHESSBOARD

LESSON 2: THE INCLUSION-EXCLUSION PRINCIPLE

CSE 573 Problem Set 1. Answers on 10/17/08

Problem A. First Mission

Problem D Daydreaming Stockbroker

A CLASSIFICATION OF QUADRATIC ROOK POLYNOMIALS

Chapter 3 PRINCIPLE OF INCLUSION AND EXCLUSION

2012 Math Day Competition

Problem F. Chessboard Coloring

Some results on Su Doku

Review I. October 14, 2008

Fall 2018 #8 DFS-Strong-Comps. A. Cut 'em all! 1 second, 256 megabytes

Homework Assignment #1

COCI 2008/2009 Contest #3, 13 th December 2008 TASK PET KEMIJA CROSS MATRICA BST NAJKRACI

COCI 2008/2009 Contest #6, 7 th March 2009 TASK BUKA BAZEN NERED CUSKIJA DOSTAVA SLICICE

Grade 7/8 Math Circles Game Theory October 27/28, 2015

Problem 2A Consider 101 natural numbers not exceeding 200. Prove that at least one of them is divisible by another one.

FRI Summer School Final Contest. A. Flipping Game

Problem Set 7: Games Spring 2018

BMT 2018 Combinatorics Test Solutions March 18, 2018

If a word starts with a vowel, add yay on to the end of the word, e.g. engineering becomes engineeringyay

Problems translated from Croatian by: Paula Gombar

Welcome to our first of webinars that we will. be hosting this Fall semester of Our first one

Learning Log Title: CHAPTER 2: ARITHMETIC STRATEGIES AND AREA. Date: Lesson: Chapter 2: Arithmetic Strategies and Area

Examination paper for TDT4120 Algorithms and Data Structures

Problem A. Subway Tickets

The 2016 ACM-ICPC Asia China-Final Contest Problems

2016 Canadian Computing Olympiad Day 2, Problem 1 O Canada

Eleventh Annual Ohio Wesleyan University Programming Contest April 1, 2017 Rules: 1. There are six questions to be completed in four hours. 2.

LEVEL I. 3. In how many ways 4 identical white balls and 6 identical black balls be arranged in a row so that no two white balls are together?

Math Circle Beginners Group May 22, 2016 Combinatorics

N-Queens Problem. Latin Squares Duncan Prince, Tamara Gomez February


Final Practice Problems: Dynamic Programming and Max Flow Problems (I) Dynamic Programming Practice Problems

Fun and Games on a Chess Board

Chained Permutations. Dylan Heuer. North Dakota State University. July 26, 2018

Math is Cool Masters

MATHCOUNTS g 42 nd Mock Mathcounts g

Math Circle Beginners Group May 22, 2016 Combinatorics

Lecture 20: Combinatorial Search (1997) Steven Skiena. skiena

Chapter 4. Linear Programming. Chapter Outline. Chapter Summary

Solutions of problems for grade R5

UCF Local Contest August 31, 2013

Q i e v e 1 N,Q 5000

Angles with Parallel Lines Topic Index Geometry Index Regents Exam Prep Center

COCI 2008/2009 Contest #2, 15 th November 2008 TASK KORNISLAV RESETO PERKET SVADA SETNJA CAVLI

A Graph Theory of Rook Placements

Which Rectangular Chessboards Have a Bishop s Tour?

Ivan Guo.

UNIT 1 Indices Activities

Topic 10 Recursive Backtracking

I.M.O. Winter Training Camp 2008: Invariants and Monovariants

BRITISH COLUMBIA SECONDARY SCHOOL MATHEMATICS CONTEST, 2006 Senior Preliminary Round Problems & Solutions

SGU 149. Computer Network. time limit per test: 0.50 sec. memory limit per test: 4096 KB input: standard input output: standard output

2. Nine points are distributed around a circle in such a way that when all ( )

Vectorworks / MiniCAD Tutorials

Duke Math Meet Individual Round

Lesson 1b Linear Equations

Past questions from the last 6 years of exams for programming 101 with answers.

Problem A: Watch the Skies!

(a) Left Right (b) Left Right. Up Up 5-4. Row Down 0-5 Row Down 1 2. (c) B1 B2 (d) B1 B2 A1 4, 2-5, 6 A1 3, 2 0, 1

Design of Parallel Algorithms. Communication Algorithms

Input. Output. Examples. Note. Input file: Output file: standard input standard output

RGB COLORS. Connecting with Computer Science cs.ubc.ca/~hoos/cpsc101

Conway s Soldiers. Jasper Taylor

UK SENIOR MATHEMATICAL CHALLENGE

HEXAGON. Singapore-Asia Pacific Mathematical Olympiad for Primary Schools (Mock Test for APMOPS 2012) Pham Van Thuan

Twenty-fourth Annual UNC Math Contest Final Round Solutions Jan 2016 [(3!)!] 4

An Intuitive Approach to Groups

Counting Things. Tom Davis March 17, 2006

Solutions to Exercises on Page 86

Junior Circle Games with coins and chessboards

SAMPLE !!CAUTION!! THIS IS ONLY A SAMPLE PAPER !!CAUTION!! THIS PAPER IS MEANT ONLY FOR PRACTICE

The Senior Portrait Telechart

Problem A To and Fro (Problem appeared in the 2004/2005 Regional Competition in North America East Central.)

arxiv: v1 [math.co] 24 Nov 2018

MITOCW watch?v=fp7usgx_cvm

Three of these grids share a property that the other three do not. Can you find such a property? + mod

PRIMES STEP Plays Games

Organization Team Team ID# If each of the congruent figures has area 1, what is the area of the square?

What is the sum of the positive integer factors of 12?

The lump sum amount that a series of future payments is worth now; used to calculate loan payments; also known as present value function Module 3

Ivan Guo. Broken bridges There are thirteen bridges connecting the banks of River Pluvia and its six piers, as shown in the diagram below:

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Algorithms and Game Theory Date: 12/4/14

Second Annual University of Oregon Programming Contest, 1998

Problem C The Stern-Brocot Number System Input: standard input Output: standard output

INTERNATIONAL MATHEMATICS TOURNAMENT OF TOWNS Junior A-Level Paper, Spring 2014.

In the game of Chess a queen can move any number of spaces in any linear direction: horizontally, vertically, or along a diagonal.

Asymptotic Results for the Queen Packing Problem

International Contest-Game MATH KANGAROO Canada, 2007

2016 Fortune 500 Sponsorship Guide

Overview. Equipment. Setup. A Single Turn. Drawing a Domino

Combinations and Permutations

Study Guide: 5.3 Prime/Composite and Even/Odd

12th Bay Area Mathematical Olympiad

EIGHT STEPS TO GUARANTEE A GOOD CLIENT CALL

Olympiad Combinatorics. Pranav A. Sriram

Transcription:

Problem Set 7: Network Flows 15-295 Fall 2018 A. Soldier and Traveling time limit per test: 1 second memory limit per test: 256 megabytes : standard : standard In the country there are n cities and m bidirectional roads between them. Each city has an army. Army of the i-th city consists of a i soldiers. Now soldiers roam. After roaming each soldier has to either stay in his city or to go to the one of neighboring cities by at moving along at most one road. Check if is it possible that after roaming there will be exactly b i soldiers in the i-th city. First line of consists of two integers n and m (1 n 100, 0 m 200). Next line contains n integers a, a,..., a (0 a 100). Next line contains n integers b, b,..., b (0 b 100). Then m lines follow, each of them consists of two integers p and q (1 p, q n, p q) denoting that there is an undirected road between cities p and q. It is guaranteed that there is at most one road between each pair of cities. If the conditions can not be met single word "NO". Otherwise word "YES" and then n lines, each of them consisting of n integers. Number in the i-th line in the j-th column should denote how many soldiers should road from city i to city j (if i j) or how many soldiers should stay in city i (if i = j). n i n i If there are several possible answers you may any of them. Examples Copy 4 4 6 3 3 5 3 1 2 3 3 4 4 2 YES 1 0 0 0 2 0 0 0 0 5 1 0 0 0 Copy 2 0 NO

Problem B. J. Students Initiation Time limit: Memory limit: 2 seconds 256 megabytes Soon the first year students will be initiated into students at the University of Berland. The organizers of the initiation come up with a program for this holiday. In their opinion, it would be good if the first-year students presented small souvenirs to each other. When they voiced this idea to the first-year students, they found out the following: some pairs of the new students already know each other; each new student agrees to give souvenirs only to those with whom they are already familiar; each new student does not want to present too many souvenirs. The organizers have written down all the pairs of first-year friends who are familiar with each other and now want to determine for each new student, whom they should give souvenirs to. In their opinion, in each pair of familiar students exactly one student must present a souvenir to another student. First year students already decided to call the unluckiest the one who will have to present the greatest number of souvenirs. The organizers in return promised that the unluckiest will be unlucky to the minimum possible degree: of course, they will have to present the greatest number of souvenirs compared to the other students, but this number will be as small as possible. Organizers are very busy, and they asked you to determine for each pair of first-year friends who and to whom should present a souvenir. The first line contains two integers n and m (1 n 5000, 0 m min(5000,n (n 1)/2)) the number of the first year students and the number of pairs of the students that know each other. The students are numbered from 1 to n. Each of the following m lines contains two integers x i,y i (1 x i,y i n, x i y i ) the students in each pair. It is guaranteed that each pair is present in the list exactly once. It is also guaranteed that if there is a pair (x i,y i ) in the list, then there is no pair (y i,x i ). Print a single integer into the first line the smallest number of souvenirs that the unluckiest student will have to present. Following should be m lines, each containing two integers the students which are familiar with each other. The first number in the pair must be the student that will present the souvenir to the second student in the pair. Pairs can be printed in any order. If there are many solutions, print any of them.

Examples 5 4 1 3 2 3 2 5 standard 1 2 3 3 1 5 2 standard 4 3 1 3 1 4 1 1 4 3 1 4 6 4 1 4 2 3 2 4 3 1 3 2 1 3 2 4 3 2 4 1 4 3

Problem GC Apple Market You are managing a market with some stores. The stores are arranged in an n m grid. Each store sells apples. Apples cost exactly 1 Malaysian Ringgit per apple at every store. There will be several customers who walk through this market. Each customer will only visit stores within a subrectangle of the market, and each customer has a fixed amount of money to spend. Also, each store has a limited inventory of apples, which will not be replenished between customers; the number available differs from store to store. Assuming you can control how many apples each store sells to each customer, what is the most money you can make? Each will consist of a single test case. Note that your program may be run multiple times on different s. The first line of will contain three space-separated integers n, m, and k, where the market has n rows and m columns (1 apple n, m apple 50), and there will be k (1 apple k apple 10 5 ) customers. Each of the next n lines will have m integers a (0 apple a apple 10 9 ). This is a matrix in row major order, indicating the number of apples in the inventory of each store. a[r, c] is the number of apples in the store in the r th row, c th column. The rows range from 1..n and the columns from 1..m. The top left corner is a[1, 1], and the bottom right corner is a[n, m]. Each of the next k lines will describe a customer, with five integers: t, b (1 apple t apple b apple n), l, r (1 apple l apple r apple m), and x (0 apple x apple 10 9 ). The customer will only shop in the subrectangle from (t, l) to (b, r) inclusive (t=top, b=bottom, l=left, r=right). The customer has exactly x Malaysian Ringgits to spend. a single integer, representing the maximum amount of money to be made by controlling how many items each store sells to each customer.

Sample 1 Sample 1 2 3 2 3 4 5 6 2 3 20 2 3 15 20

D. Binary Tree on Plane time limit per test: 3 seconds memory limit per test: 256 megabytes : standard : standard A root tree is a directed acyclic graph that contains one node (root), from which there is exactly one path to any other node. A root tree is binary if each node has at most two outgoing arcs. When a binary tree is painted on the plane, all arcs should be directed from top to bottom. That is, each arc going from u to v must meet the condition y > y. You've been given the coordinates of all tree nodes. Your task is to connect these nodes by arcs so as to get the binary root tree and make the total length of the arcs minimum. All arcs of the built tree must be directed from top to bottom. The first line contains a single integer n (2 n 400) the number of nodes in the tree. Then follow n lines, two integers per line: x, y ( x, y 10 ) coordinates of the nodes. It is guaranteed that all points are distinct. i i i i 3 u v If it is impossible to build a binary root tree on the given points, print "-1". Otherwise, print a single real number the total length of the arcs in the minimum binary tree. The answer will be considered correct if the absolute or relative - 6 error doesn't exceed 10. Examples Copy 3 0 0 1 0 3.650281539872885 Copy 4 0 0 1 0 2 0-1

E. Almost Permutation 3 seconds, 512 megabytes Recently Ivan noticed an array a while debugging his code. Now Ivan can't remember this array, but the bug he was trying to fix didn't go away, so Ivan thinks that the data from this array might help him to reproduce the bug. Ivan clearly remembers that there were n elements in the array, and each element was not less than 1 and not greater than n. Also he remembers q facts about the array. There are two types of facts that Ivan remembers: 1 l i r i v i for each x such that l i x r i a x v i; 2 l r v for each x such that l x r a v. Also Ivan thinks that this array was a permutation, but he is not so sure about it. He wants to restore some array that corresponds to the q facts that he remembers and is very similar to permutation. Formally, Ivan has denoted the cost of array as follows:, where cnt(i) is the number of occurences of i in the array. Help Ivan to determine minimum possible cost of the array that corresponds to the facts! The first line contains two integer numbers n and q (1 n 50, 0 q 100). Then q lines follow, each representing a fact about the array. i-th line contains the numbers t i, l i, r i and v i for i-th fact (1 t 2, 1 l r n, 1 v n, t denotes the type of the fact). If the facts are controversial and there is no array that corresponds to them, print -1. Otherwise, print minimum possible cost of the array. 3 0 3 3 1 1 1 3 2 5 3 2 1 1 3 2 3 2 9 3 2 1 1 3 2 3 1-1 i i i i i x i i i i i i

F. Oleg and chess 6.5 seconds, 256 megabytes Oleg the bank client solves an interesting chess problem: place on n n chessboard the maximum number of rooks so that they don't beat each other. Of course, no two rooks can share the same cell. Remind that a rook standing in the cell (a, b) beats a rook standing in the cell (x, y) if and only if a = x or b = y. Unfortunately (of fortunately?) for Oleg the answer in this problem was always n, so the task bored Oleg soon. He decided to make it more difficult by removing some cells from the board. If a cell is deleted, Oleg can't put a rook there, but rooks do beat each other "through" deleted cells. Oleg deletes the cells in groups, namely, he repeatedly choose a rectangle with sides parallel to the board sides and deletes all the cells inside the rectangle. Formally, if he chooses a rectangle, lower left cell of which has coordinates (x 1, y 1), and upper right cell of which has coordinates (x 2, y 2), then he deletes all such cells with coordinates (x, y) that x x x and y y y. It is guaranteed that no cell is deleted twice, i.e. the chosen rectangles do not intersect. This version of the problem Oleg can't solve, and his friend Igor is busy at a conference, so he can't help Oleg. You are the last hope for Oleg! Help him: given the size of the board and the deleted rectangles find the maximum possible number of rooks that could be placed on the board so that no two rooks beat each other. The first line contains single integer n (1 n 10000) the size of the board. The second line contains single integer q (0 q 10000) the number of deleted rectangles. The next q lines contain the information about the deleted rectangles. Each of these lines contains four integers x, y, x and y (1 x x n, 1 y y n) the coordinates 1 2 of the lower left and the upper right cells of a deleted rectangle. If is guaranteed that the rectangles do not intersect. In the only line print the maximum number of rooks Oleg can place on the board so that no two rooks beat each other. 5 5 1 1 1 3 1 5 4 1 5 5 2 5 2 5 3 2 3 5 3 8 4 2 2 4 6 1 8 1 8 7 1 8 2 5 4 6 8 8

Here is the board and the example of rooks placement in the first example: