Codeforces Spyke Chatting

Description

The R2 company has n employees working for it. The work involves constant exchange of ideas, sharing the stories of success and upcoming challenging. For that, R2 uses a famous instant messaging program Spyke.

R2 has m Spyke chats just to discuss all sorts of issues. In each chat, some group of employees exchanges messages daily. An employee can simultaneously talk in multiple chats. If some employee is in the k-th chat, he can write messages to this chat and receive notifications about messages from this chat. If an employee writes a message in the chat, all other participants of the chat receive a message notification.

The R2 company is conducting an audit. Now the specialists study effective communication between the employees. For this purpose, they have a chat log and the description of chat structure. You, as one of audit specialists, are commissioned to write a program that will use this data to determine the total number of message notifications received by each employee.

Input

The first line contains three space-separated integers nm and k(2 ≤ n ≤ 2·104; 1 ≤ m ≤ 10; 1 ≤ k ≤ 2·105) — the number of the employees, the number of chats and the number of events in the log, correspondingly.

Next n lines contain matrix a of size n × m, consisting of numbers zero and one. The element of this matrix, recorded in the j-th column of the i-th line, (let's denote it as aij) equals 1, if the i-th employee is the participant of the j-th chat, otherwise the element equals 0. Assume that the employees are numbered from 1 to n and the chats are numbered from 1 to m.

Next k lines contain the description of the log events. The i-th line contains two space-separated integers xi and yi(1 ≤ xi ≤ n; 1 ≤ yi ≤ m) which mean that the employee number xi sent one message to chat number yi. It is guaranteed that employee number xi is a participant of chat yi. It is guaranteed that each chat contains at least two employees.

Output

Print in the single line n space-separated integers, where the i-th integer shows the number of message notifications the i-th employee receives.

Sample Input

Input
3 4 5
1 1 1 1
1 0 1 1
1 1 0 0
1 1
3 1
1 3
2 4
3 2
Output
3 3 1 
Input
4 3 4
0 1 1
1 0 1
1 1 1
0 0 0
1 2
2 1
3 1
1 3
Output
0 2 3 0 

题目大意:n个人,m种聊天器,k次发送消息,然后给出n*m的矩阵,如果g[i][j]为1,则表示i号人会使用j号聊天器,接着给出k次消息发送者和聊天器,如果i在j种聊天器上发送了一条消息,那么所有使用j种聊天器的人都会接受到消息。现在要求每个人会接受到几条消息,自己发送的不算。

<span style="font-size:14px;">#include<iostream>
#include <string.h>
using namespace std;
int a[200010][20];
int num1[200010];
int num2[20];
int main()
{
    int n,m,k;
    int a1,a2;
    while (cin>>n>>m>>k)
    {
        memset(num1, 0, sizeof(num1));
        memset(num2, 0, sizeof(num2));
        for (int i=1;i<=n; i++)
        {
            for (int j=1; j<=m; j++)
            {
                cin>>a[i][j];
            }
        }
        for (int i=0; i<k; i++)
        {
            cin>>a1>>a2;
            num1[a1]++;
            num2[a2]++;
        }
        int sum;
        for (int i=1; i<=n; i++)
        {
            sum=0;
            for (int j=1; j<=m; j++)
            {
                if(a[i][j])
                {
                    sum+=num2[j];
                }
            }
            num1[i]=sum-num1[i];
        }
        for (int i=1; i<=n; i++)
        {
            if(i==n)
            {
                cout<<num1[i]<<endl;
                continue;
            }
            cout<<num1[i]<<" ";
        }
    }
    return 0;
}</span>







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值