https://hihocoder.com/problemset/problem/1175
Time limit: 10000ms
Single point time limit: 1000ms
Memory limit: 256MB
The campus network of the school where Xiao Hi and Xiao Ho are located was hacked and a virus was dropped. This matter immediately aroused everyone's discussion on the school BBS, of course, Xiao Hi and Xiao Ho also participated in it. From what everyone knows, Xiao Hi and Xiao Ho have compiled the following information:
For example, suppose that the school network is composed of 4 nodes and 4 links as shown in the figure below after cutting off some network connections. Initially, only node 1 had a virus.

Initially, node 1 transmitted a virus to node 2 and node 3, leaving 1 virus:

After one of the viruses reached node 2, a virus was transmitted to node 3. Another virus that reaches node 3 sends its own copy to node 4:

When the virus transmitted from node 2 to node 3 arrives, the virus sends a copy of itself to node 4. At this time, there are 2 viruses left on node 3:

The final virus on each node is:

According to the current situation, Little Hi and Little Ho discovered that after a period of time, the number of viruses on all nodes will definitely not change. So for the entire network, how many viruses will there be in the end?
Tip: Application of topological sorting
Line 1: 3 integers N, M, K, 1≤K≤N≤100,000, 1≤M≤500,000
Line 2: K integers A [i], A [i] means that the hacker put a virus on node A [i]. 1≤A [i] ≤N
Line 3: M + 2: 2 integers u, v per line, indicating that there is a network link from node u to node v. The data is guaranteed to be an acyclic graph. 1≤u, v≤N
Line 1: An integer representing the number of viruses in the entire network at the end MOD 142857
4 4 1
1
1 2
1 3
2 3
3 4
6
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;
const int nmax=1e5+10;
int inDegree [nmax]; // Save the in-degree of each node
int virus [nmax]; // Record the virus number of each node
vector <int> G [nmax]; // Adjacency list
const int mod=142857;
int n, m, k; // Number of points, number of edges
void toposort(){
queue<int>q;
while (! q.empty ()) q.pop (); // Empty the queue
for (int i = 1; i <= n; i ++) {// Vertex number: 1 ~ N
if(inDegree[i]==0){
q.push (i); // Throw vertices with a degree of 0 into the queue
}
}
while(!q.empty()){
int u=q.front();
q.pop (); // Delete the point
for (int i = 0; i <G [u] .size (); i ++) {// Traverse all edges adjacent to point u and delete it.
int v=G[u][i];
inDegree[v]--;
if(inDegree[v]==0){
q.push(v);
}
virus[v]=(virus[v]+virus[u])%mod;
}
G[u].clear();
}
}
int main(int argc, char** argv) {
while(scanf("%d %d %d",&n,&m,&k)!=EOF){
memset(inDegree,0,sizeof(inDegree));
memset(virus,0,sizeof(virus));
for (int i = 1; i <= n; i ++) {// Initialize and clear the adjacency list
G[i].clear();
}
while(k--){
int x;
scanf("%d",&x);
virus [x] ++; // Place the initialization virus
}
int u,v;
for(int i=0;i<m;i++){
scanf("%d %d",&u,&v);
G[u].push_back(v);
inDegree[v]++;
}
toposort();
int ans=0;
for(int i=1;i<=n;i++){
ans=(ans+virus[i])%mod;
}
printf("%d\n",ans);
}
return 0;
}
https://hihocoder.com/problemset/problem/1174 # 1174: a topological sorting · Time limit: 10000ms A single point of time: 1000ms Memory Limit: 256MB description As today's class teacher of spec...
Title: Chinese title. Hey. (I actually want to post a link to a topic every time I write a blog, but I forgot about it every time >.<), just give you n points and m edges (DAG), he will put the ...
hihoCoder # 1174 a topological sorting · answer: Bare title topological sort, since the su...
# 1174: a topological sorting · Time limit: 10000ms A single point of time: 1000ms Memory Limit: 256MB description As today's class teacher of special boring, small and small Hi Ho secretly tal...
description As today's class teacher of special boring, small and small Hi Ho secretly talking. Small Ho: Small Hi, this semester you have what lessons it? Small Hi: a lot of, such as XXX1, XXX2 there...
Title link:http://hihocoder.com/problemset/problem/1175 time limit:10000ms Single point time limit:1000ms Memory limit:256MB description The campus network of the school where Xiao Hi and Xiao Ho are ...
hihoCoder 1175 topological sort Title link: https://hihocoder.com/problemset/problem/1175 1. Topic analysis This question is a typical topological sorting question. This question can be solved either ...
description hihocoder 1175 Ideas answer...
description The campus network of the school where Xiao Hi and Xiao Ho are located was hacked and put a virus. This matter immediately aroused everyone's discussion on the school's BBS. Of course, Xia...
Title link:http://hihocoder.com/problemset/problem/1174 #1174: Topological sorting·One time limit:10000ms Single point time limit:1000ms Memory limit:256MB description Because the teacher in cl...