为什么本地会报202？

@Cothrax 2016-07-22 10:57 回复

uses math;
type
edge=record
f,t:integer;
end;
var
n,m,used,ans,i:longint; //n个顶点, m条边
rcd:array[-1..1] of longint;
g:array[0..200001] of edge;
first:array[0..10001] of longint;
color:array[0..10001] of -1..1;

procedure star(); //前向星
var
tmp:array[0..200001] of edge;
count:array[0..10001] of longint;
i:longint;
begin
fillchar(count,sizeof(count),0);
for i:=1 to m do begin
tmp[m+i].f:=tmp[i].t;tmp[m+i].t:=tmp[i].f;
inc(count[tmp[i].f]);inc(count[tmp[i].t]);
end;
first[1]:=1;
for i:=2 to n do begin
inc(count[i],count[i-1]);
first[i]:=count[i-1]+1;
end;
first[n+1]:=count[n]+1;
for i:=1 to 2*m do begin
g[count[tmp[i].f]]:=tmp[i];
dec(count[tmp[i].f]);
end;
end;

function dfs(v:longint;c:integer):boolean; //染色
var i:longint;
begin
color[v]:=c;
dfs:=true;
for i:=first[v] to first[v+1]-1 do
if (color[g[i].t]=c) or ((color[g[i].t]=0) and not dfs(g[i].t,-c)) then exit(false);
inc(rcd[c]);
end;

begin
star();
used:=0; //已染色点数
ans:=0; //答案

while used<n do begin
fillchar(rcd,sizeof(rcd),0);
for i:=1 to n do
if color[i]=0 then
if dfs(i,1) then break
else begin write('Impossible');halt end;
inc(ans,min(rcd[-1],rcd[1]));
inc(used,rcd[-1]+rcd[1]);
end;
write(ans);
end.
@ddd 管理员 2016-07-22 11:41 回复 举报

Windows下的栈比较小 当时NOIP2015D1T2在Windows下就爆栈 但是CCF测出来就没事