[Codeforces Round #588 (Div. 2)]F. Konrad and Company Evaluation(图论)

有i个人,m对两两之间的关系,第i个人初始的薪水为i,有q次操作,第i次操作会把v[i]号的薪水提升成n+i
如果两个人之间存在关系,薪水高的会向薪水低的炫耀
定义u,v,w为一个三元组,当u向v炫耀,v向w炫耀
要求每次操作后输出当前三元组个数

把a鄙视b看成a->b的边,每个点作为中间点贡献是入度×出度,vector记下返边,每次更改x,都是把到x的边变成x起点的边。

import java.io.*;
import java.util.Scanner;
import java.util.Vector;
 
public class Main {
    static long cd[] = new long[100100],rd[] = new long[100100];
    public static void main(String[] args) throws IOException{
        Scanner cin=new Scanner(System.in);
        PrintWriter cout = new PrintWriter(System.out);
        int n = cin.nextInt(),m = cin.nextInt();
        Vector []g = new Vector[100100];
        for (int i = 1; i <= n; i++) {
            g[i] = new Vector();
        }
        for (int i = 1; i <= m; i++) {
            int u = cin.nextInt(),v = cin.nextInt();
            if (u > v) {
                int t = u;
                u = v;
                v = t;
            }
            rd[u]++; cd[v]++;
            g[u].addElement(v);
        }
        long ans = 0;
        for (int i = 1; i <= n; i++) ans += rd[i]*cd[i];
        int q = cin.nextInt();
        cout.print(ans+"\n");
        while (q-- != 0) {
            int t = cin.nextInt();
            ans -= rd[t]*cd[t];
            for (int i = 0; i < g[t].size(); i++) {
                int pos = (int) g[t].elementAt(i);
                ans -= rd[pos]*cd[pos];
                cd[pos]--; cd[t]++;
                rd[pos]++; rd[t]--;
                ans += rd[pos]*cd[pos];
                g[pos].addElement(t);
            }
            g[t].clear();
            cout.print(ans+"\n");
        }
        cin.close(); cout.close();
    }
}

Konrad is a Human Relations consultant working for VoltModder, a large electrical equipment producer. Today, he has been tasked with evaluating the level of happiness in the company.
There are
people working for VoltModder, numbered from to . Each employee earns a different amount of money in the company — initially, the -th person earns
rubles per day.
On each of
following days, the salaries will be revised. At the end of the -th day, employee will start earning
rubles per day and will become the best-paid person in the company. The employee will keep his new salary until it gets revised again.
Some pairs of people don’t like each other. This creates a great psychological danger in the company. Formally, if two people
and dislike each other and earns more money than , employee will brag about this to . A dangerous triple is a triple of three employees , and , such that brags to , who in turn brags to . If dislikes , then dislikes
.
At the beginning of each day, Konrad needs to evaluate the number of dangerous triples in the company. Can you help him do it?

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值