Input The first line of the input contains two integers n and m separated by a single space. n denotes the number of Dan's students and m denotes the number of events. The second line contains n letters separated by single spaces. The i-th letter is either "A" or "B". If it's "A", the i-th student is initially in group A; Otherwise, the i-th student is initially in group B. The next m lines describe the events in chronological order. Each line describes a single event. If a line starts with the string cite, two integers x and y follow, indicating that student x has published a paper in which they cite student y's work. Otherwise, the line starts with the string change, which is followed by a single integer x. This indicates that Dan has changed student x's group. Output Print two integers separated by a single space. These should indicate the final citation scores of groups A and B, respectively. Sample Input 1 65 AABBBB cite 1 3 cite 12 change 1 cite 2 1 cite 4 2 Sample Output 1 6 10 Sample 1 Explanation • The first line indicates that there are 6 students and 5 events. • The second line indicates that the first two students are in group A while the remaining four are in group B. • In the first event, student 1 cites student 3's work. Since they are in different groups, group B (student 3's group) scores 5 points. • Student 1 cites student 2's work. Since they are both in group A, group A scores 1 point. • Dan changes student 1's group (from group A to group B). • Student 2 then cites student 1's work. Group B scores 5 points. • Finally, student 4 cites student 2's work. Group A scores 5 points. • In total, group A scores 6 points and group B scores 10 points, which is reflected in the output. Sample Input 2 36 A A A cite 3 1 change 1 cite 1 2 change 1 change 2 cite 2 1 Sample Output 2 11 0

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Input
The first line of the input contains two integers n and m separated by a single
space. n denotes the number of Dan's students and m denotes the number of
events.
The second line contains n letters separated by single spaces. The i-th letter is
either "A" or "B". If it's "A", the i-th student is initially in group A; Otherwise, the
i-th student is initially in group B.
The next m lines describe the events in chronological order. Each line describes a
single event. If a line starts with the string cite, two integers x and y follow,
indicating that student x has published a paper in which they cite student y's
work.
Otherwise, the line starts with the string change, which is followed by a single
integer x. This indicates that Dan has changed student x's group.
Output
Print two integers separated by a single space. These should indicate the final
citation scores of groups A and B, respectively.
Sample Input 1
65
AABBBB
cite 1 3.
cite 1 2
change 1
cite 2 1
cite 4 2
Sample Output 1
6 10
Sample 1 Explanation
• The first line indicates that there are 6 students and 5 events.
• The second line indicates that the first two students are in group A while the
remaining four are in group B.
• In the first event, student 1 cites student 3's work. Since they are in different
groups, group B (student 3's group) scores 5 points.
• Student 1 cites student 2's work. Since they are both in group A, group A
scores 1 point.
Dan changes student 1's group (from group A to group B).
• Student 2 then cites student 1's work. Group B scores 5 points.
• Finally, student 4 cites student 2's work. Group A scores 5 points.
• In total, group A scores 6 points and group B scores 10 points, which is
reflected in the output.
Sample Input 2
36
A A A
cite 3 1
change 1
cite 1 2
change 1
change 2
cite 2 1
Sample Output 2
11 0
Transcribed Image Text:Input The first line of the input contains two integers n and m separated by a single space. n denotes the number of Dan's students and m denotes the number of events. The second line contains n letters separated by single spaces. The i-th letter is either "A" or "B". If it's "A", the i-th student is initially in group A; Otherwise, the i-th student is initially in group B. The next m lines describe the events in chronological order. Each line describes a single event. If a line starts with the string cite, two integers x and y follow, indicating that student x has published a paper in which they cite student y's work. Otherwise, the line starts with the string change, which is followed by a single integer x. This indicates that Dan has changed student x's group. Output Print two integers separated by a single space. These should indicate the final citation scores of groups A and B, respectively. Sample Input 1 65 AABBBB cite 1 3. cite 1 2 change 1 cite 2 1 cite 4 2 Sample Output 1 6 10 Sample 1 Explanation • The first line indicates that there are 6 students and 5 events. • The second line indicates that the first two students are in group A while the remaining four are in group B. • In the first event, student 1 cites student 3's work. Since they are in different groups, group B (student 3's group) scores 5 points. • Student 1 cites student 2's work. Since they are both in group A, group A scores 1 point. Dan changes student 1's group (from group A to group B). • Student 2 then cites student 1's work. Group B scores 5 points. • Finally, student 4 cites student 2's work. Group A scores 5 points. • In total, group A scores 6 points and group B scores 10 points, which is reflected in the output. Sample Input 2 36 A A A cite 3 1 change 1 cite 1 2 change 1 change 2 cite 2 1 Sample Output 2 11 0
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Program on Numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education