In response to popular demand, Dan’s established two research groups A and B composed of his n graduate students. Each of these students is a member of exactly one of the two groups at any given time. The students are numbered from 1 to n in some arbitrary order. To measure the success of his research groups, Dan assigns a citation score to each of them. Initially, both groups have citation score 0. Throughout the semester, events of the following two types happen: Studentxpublishesapaperinwhichtheycitestudenty’swork(youcan assume all of the students have been around long enough to have prior research that can be cited). As a result, If x and y are in the same group, their group’s citation score increases by 1. If x and y are in different groups, y’s group’s citation score increases by 5. Danchangesstudentx’sgroup(fromAtoBorfromBtoA)tohavethem work on different projects. To assess the overall success of the research groups, Dan needs to calculate their final citation scores at the end of the semester. Help him do so by writing a program that reports the final scores given a description of the events occurring throughout the semester. Filename Your filename for this question must be q1.py. 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.

Operations Research : Applications and Algorithms
4th Edition
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Wayne L. Winston
Chapter19: Probabilistic Dynamic Programming
Section19.4: Further Examples Of Probabilistic Dynamic Programming Formulations
Problem 7P
icon
Related questions
Question

In response to popular demand, Dan’s established two research groups A and B composed of his n graduate students. Each of these students is a member of exactly one of the two groups at any given time. The students are numbered from 1 to n in some arbitrary order.

To measure the success of his research groups, Dan assigns a citation score to each of them. Initially, both groups have citation score 0. Throughout the semester, events of the following two types happen:

  1. Studentxpublishesapaperinwhichtheycitestudenty’swork(youcan assume all of the students have been around long enough to have prior research that can be cited). As a result,

    If x and y are in the same group, their group’s citation score increases by 1.

    If x and y are in different groups, y’s group’s citation score increases by 5.

  2. Danchangesstudentx’sgroup(fromAtoBorfromBtoA)tohavethem

    work on different projects.

To assess the overall success of the research groups, Dan needs to calculate their final citation scores at the end of the semester. Help him do so by writing a program that reports the final scores given a description of the events occurring throughout the semester.

Filename

Your filename for this question must be q1.py.

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.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

When I go to type my input it does let me add a single space also the second line here 
m = int(input()) it's not supposed to be an integer. 

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Topological Sort
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
Operations Research : Applications and Algorithms
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole