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.
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.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
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.