有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?