CSC3100 Data Structures Spring 2024 Assin4
CSC3100 Data Structures Spring 2024 Assin4
Requirements
Code (90%)
You can write your code in Java, Python, C, or C++. The time limit may vary among different
languages, depending on the performance of the language. Your code must be a complete excutable
program instead of only a function. We guarantee test data strictly compliance with the requirements
in the description, and you do not need to deal with cases where the input data is invalid.
Libraries in this assignment:
• For C/C++, you can only include standard library.
• For Java, you can only import java.util.*
• For Python, you can only import standard library. In other words, you cannot import libraries
such as numpy.
Report (10%)
You also need to write a report in pdf type to explain the following:
• What are the possible solutions for the problem?
• How do you solve this problem?
• Why is your solution better than others?
Please note that the maximum number of pages allowed for your report is 5 pages.
Remember that the report is to illustrate your thinking process. Keep in mind that your report is
supposed to show your ideas and thinking process. We expect clear and precise textual descriptions
in your report, and we do not recommend that you over-format your report.
Input
Two integers in one line: A, and B
Output
One integer: A + B
1
Solutions
Java
import java . util .*;
Python
AB = input (). split ()
A , B = int ( AB [0]) , int ( AB [1])
print ( A + B )
C
# include < stdio .h >
C++
# include < iostream >
C. Submission
After finishing this assignment, you are required to submit your code to the Online Judge System
(OJ), and upload your .zip package of your code files and report to BlackBoard.
2
Note: The program running time may vary on different machines. Please refer to the result of
the online judge system. OJ will show the time and memory limits for different languages on the
corresponding problem page.
If you have other questions about the online judge system, please refer to OJ wiki (campus network
only). If this cannot help you, feel free to contact us.
C.2 BlackBoard
You are required to upload your source codes and report to the BlackBoard platform. You need
to name your files according to the following rules and compress them into A1_<Student ID>.zip :
A1_ < Student ID >. zip
| - - A1_P1_ < Student ID >. java / py / c / cpp
| - - A1_P2_ < Student ID >. java / py / c / cpp
| - - A1_Report_ < Student ID >. pdf
For Java users, you don’t need to consider the consistency of class name and file name.
For example, suppose your ID is 123456789, and your problem 1 is written in Python, problem 2 is
written in Java then the following contents should be included in your submitted A1_123456789.zip:
A1_123456789 . zip
| - - A1 _P 1_ 1 23 45 67 8 9 . py
| - - A1 _P 2_ 1 23 45 67 8 9 . java
| - - A 1 _ R e p o r t _ 1 2 3 4 5 6 7 8 9 . pdf
FAQs
Q: I cannot access to Online Judge.
A: First, please ensure that you are using the campus network. If you are not on campus, please use
the university VPN. Second, please delete cookies and refresh browser or use other browser. If you
still cannot access to Online Judge, try to visit it via the IP address 10.26.200.13.
Q: My program passes samples on my computer, but not get AC on OJ.
A: Refer to OJ Wiki Q&A
Authors
If you have questions for the problems below, please contact:
• Problem 1. The 2024 Programming Contest of CUHK-Shenzhen (official)
• Problem 2. Yingli Zhou: [email protected] Ziyi Zhao: [email protected]
3
CSC3100 Data Structures Spring 2024
Programming Assignment 3
1.2 Input
The first line of the input contains an integer T , representing the number of test cases. Each test case
is given as follows:
• The first line contains an integer N (N ≥ 1), denoting the number of vertices in the tree.
• The second line contains N − 1 integers p2 , p3 , . . . , pN (1 ≤ pi ≤ i − 1), where pi denotes the
parent of vertex i in T .
• The third line contains a permutation A of [N ]. It is guaranteed that the first element of A is 1.
4
1.3 Output
For each test case, output a single line containing either ”YES” or ”NO”, indicating whether the given
permutation can be a valid DFS order of T .
2.2 Input
The first line contains two integers N, W .
The following N lines, each line with N integers. The jth integer in the ith line is Aij . It is guaranteed
that Aij = Aji and Aii = 0.
2.3 Output
Output the least money Piggy needs to pay.
5
2.4 Problem Scale & Subtasks
0 ≤ Aij , W ≤ 1000
Hint
Try to transform the problem to a spanning tree problem.