BZOJ 1023

program bzoj1023;
uses math;

const inf=1000000000;
    maxn=50005;
    maxm=20000005;
    
type edge=record
    togo,next:longint;
end;
    
var n,m,cnt,ind,ans,l,r:longint;
    last,deep,f,low,dfn,fa:array [0..maxn] of longint;
    a,q:array [0..maxn*2] of longint;
    e:array [0..maxm] of edge;

procedure insert(u,v:longint);
begin
  inc(cnt);
  e[cnt].togo:=v; e[cnt].next:=last[u]; last[u]:=cnt;
  inc(cnt);
  e[cnt].togo:=u; e[cnt].next:=last[v]; last[v]:=cnt;
end;

procedure dp(root,x:longint);
var tot,i:longint;
begin
    tot:=deep[x]-deep[root]+1;
    i:=x;
    while i<>root do
        begin
            a[tot]:=f[i];
            dec(tot);
            i:=fa[i];
        end;
    a[tot]:=f[root];
    tot:=deep[x]-deep[root]+1;
    for i:=1 to tot do 
        a[i+tot]:=a[i];
    q[1]:=1; l:=1; r:=1;
    for i:=2 to (tot shl 1) do
        begin
            while (l<=r) and (i-q[l]>(tot shr 1)) do
            inc(l);
            ans:=max(ans,a[i]+i+a[q[l]]-q[l]);
            while (l<=r) and (a[q[r]]-q[r]<=a[i]-i) do
                dec(r);
            inc(r);
            q[r]:=i;
        end;
    for i:=2 to tot do 
    f[tot]:=max(f[root],a[i]+min(i-1,tot-i+1));
end;

procedure dfs(x:longint);
var i:longint;
begin
    inc(ind);
    low[x]:=ind;
    dfn[x]:=ind;
    i:=last[x];
    while i<>0 do
        begin
          if e[i].togo<>fa[x] then 
            begin
                if dfn[e[i].togo]=0 then 
                    begin
                        fa[e[i].togo]:=x;
                        deep[e[i].togo]:=deep[x]+1;
                        dfs(e[i].togo);
                        low[x]:=min(low[x],low[e[i].togo]);
                    end
                else
                    low[x]:=min(low[x],dfn[e[i].togo]);
                if dfn[x]<low[e[i].togo] then 
                    begin
                      ans:=max(ans,f[x]+f[e[i].togo]+1);
                      f[x]:=max(f[x],f[e[i].togo]+1);
                    end;
            end;
          i:=e[i].next;
        end;
    i:=last[x];
    while i<>0 do 
        begin
          if (fa[e[i].togo]<>x) and (dfn[x]<dfn[e[i].togo]) then
          dp(x,e[i].togo);
          i:=e[i].next;
        end;
end;

procedure main;
var i,j,a,b,k:longint;
begin
    read(n,m);
    for i:=1 to m do 
        begin
            read(k,a);
            for j:=2 to k do 
            begin
                read(b);
                insert(a,b);
                a:=b;
            end;
        end;
    dfs(1);
    writeln(ans);
end;

begin
      main;
end.

 

转载于:https://www.cnblogs.com/logichandsome/p/4054647.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
BZOJ 2908 题目是一个数据下载任务。这个任务要求下载指定的数据文件,并统计文件中小于等于给定整数的数字个数。 为了完成这个任务,首先需要选择一个合适的网址来下载文件。我们可以使用一个网络爬虫库,如Python中的Requests库,来帮助我们完成文件下载的操作。 首先,我们需要使用Requests库中的get()方法来访问目标网址,并将目标文件下载到我们的本地计算机中。可以使用以下代码实现文件下载: ```python import requests url = '目标文件的网址' response = requests.get(url) with open('本地保存文件的路径', 'wb') as file: file.write(response.content) ``` 下载完成后,我们可以使用Python内置的open()函数打开已下载的文件,并按行读取文件内容。可以使用以下代码实现文件内容读取: ```python count = 0 with open('本地保存文件的路径', 'r') as file: for line in file: # 在这里实现对每一行数据的判断 # 如果小于等于给定整数,count 加 1 # 否则,不进行任何操作 ``` 在每一行的处理过程中,我们可以使用split()方法将一行数据分割成多个字符串,并使用int()函数将其转换为整数。然后,我们可以将该整数与给定整数进行比较,以判断是否小于等于给定整数。 最后,我们可以将统计结果打印出来,以满足题目的要求。 综上所述,以上是关于解决 BZOJ 2908 数据下载任务的简要步骤和代码实现。 希望对您有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值