英语翻译//By Lemon_TsyD#include #include #include #include using namespace std;const int MOD = 11129;const int MAXV = 50011;const int MAXE = 100011;struct Arc{int dest;Arc *next;Arc(){}Arc(int dest,Arc *next):dest(dest),next(next){}}Npool[MAXE],*

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/24 08:50:32
英语翻译//ByLemon_TsyD#include#include#include#includeusingnamespacestd;constintMOD=11129;constintMAXV=5

英语翻译//By Lemon_TsyD#include #include #include #include using namespace std;const int MOD = 11129;const int MAXV = 50011;const int MAXE = 100011;struct Arc{int dest;Arc *next;Arc(){}Arc(int dest,Arc *next):dest(dest),next(next){}}Npool[MAXE],*
英语翻译
//By Lemon_TsyD
#include
#include
#include
#include
using namespace std;
const int MOD = 11129;
const int MAXV = 50011;
const int MAXE = 100011;
struct Arc
{
int dest;
Arc *next;
Arc(){}
Arc(int dest,Arc *next):
dest(dest),next(next){}
}Npool[MAXE],*Nptr(Npool),*adj[MAXV];
int V,E;
inline int check(int i)
{
if(i >= MOD) return i%MOD;
return i;
}
int f[MAXV];
int F[MAXV];
void read()
{
int src,dest;
scanf("%d%d",&V,&E);
for(int i = 0;i < E;++i)
{
scanf("%d%d",&src,&dest);
adj[dest]= new(Nptr++) Arc(src,adj[dest]);
++f[dest];++F[src];
}
}
int g[MAXV];
void dfs(int i)
{
if(f[i]==0) g[i] = 1;
else g[i] = 0;
for(Arc* p=adj[i];p;p=p->next)
{
if(g[p->dest]==-1) dfs(p->dest);
g[i] = check(g[i]+g[p->dest]);
}
}
void dp()
{
memset(g,0xff,sizeof(g));
for(int i = 1;i

英语翻译//By Lemon_TsyD#include #include #include #include using namespace std;const int MOD = 11129;const int MAXV = 50011;const int MAXE = 100011;struct Arc{int dest;Arc *next;Arc(){}Arc(int dest,Arc *next):dest(dest),next(next){}}Npool[MAXE],*
const
MOD_=11129;
MAXV=50011;
MAXE=100011;
type
pArc=^Arc;
Arc=object
dest:longint;
next:pArc;
constructor Arc();
constructor Arc(dest_:longint; next_:pArc);
end;
constructor Arc.Arc(); begin end;
constructor Arc.Arc(dest_:longint; next_:pArc);
begin dest:=dest_; next:=next_; end;
var
Npool:array [0..MAXE] of Arc;
Nptr:pArc;
adj:array [0..MAXV] of pArc;
V,E:integer;
function check(i:longint):longint;
begin
if (i>=MOD_) then check:=i div MOD_
else check:=i;
end;
var
f,F_:array [0..MAXV] of longint;
procedure read_;
var
src,dest:longint;
i:longint;
begin
read(V,E);
for i:=0 to E-1 do
begin
read(src, dest);
new(Nptr);
Nptr^.Arc(src,adj[dest]);
inc(Nptr);
adj[dest]:=Nptr;
inc(f[dest]); inc(f_[src]);
end;
end;
var
g:array [0..MAXV] of longint;
procedure dfs(i:integer);
var
p:^Arc;
begin
if (f[i]=0) then g[i]:=1
else g[i]:=0;
p:=adj[i];
while (pnil) do begin
if g[p^.dest]=-1 then dfs(p^.dest);
g[i]:=check(g[i]+g[p^.dest]);
p:=p^.next;
end;
end;
procedure dp;
var
i:longint;
begin
fillchar(g,sizeof(g),$FF);
for i:=1 to V do
if (f_[i]=0) then dfs(i);
end;
procedure get_ans();
var
ans,i:longint;
begin
ans:=0;
for i:=1 to V do
if (f_[i]=0) then ans:=check(ans+g[i]);
writeln(ans);
end;
begin
Nptr:=@Npool;
assign(input,'foodchain.in'); reset(input);
assign(output,'foodchan.out'); rewrite(output);
read_;
dp;
get_ans;
end.