社区讨论
这道题数据过水
P1131[ZJOI2007] 时态同步参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mi6xccbo
- 此快照首次捕获于
- 2025/11/20 12:21 4 个月前
- 此快照最后确认于
- 2025/11/20 12:21 4 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
#define IL inline
#define RG register
#define gi getint()
#define gc getchar()
#define File(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
IL int getint()
{
RG int xi=0;
RG char ch=gc;
bool f=0;
while(ch<'0'|ch>'9')ch=='-'?f=1:f,ch=gc;
while(ch>='0'&ch<='9')xi=(xi<<1)+(xi<<3)+ch-48,ch=gc;
return f?-xi:xi;
}
IL void pi(int k,char ch=0)
{
if(k<0)k=-k,putchar('-');
if(k>=10)pi(k/10,0);
putchar(k%10+'0');
if(ch)putchar(ch);
}
IL unsigned int LOG2(unsigned int x)
{
unsigned int ret;
__asm__ __volatile__ ("bsrl %1, %%eax":"=a"(ret):"m"(x));
return ret;
}
const int MAX=1e6+7;
struct E{
int v,next,w;
}e[MAX<<1|1];
int n,s,f[MAX],cnt,head[MAX];
long long ans;
void add(int u,int v,int w)
{
e[++cnt]=(E){v,head[u],w};
head[u]=cnt;
}
void dfs(int p,int fa)
{
for(int i=head[p];~i;i=e[i].next)
if(e[i].v!=fa)
dfs(e[i].v,p);
for(int i=head[p];~i;i=e[i].next)
if(e[i].v!=fa)
f[p]=max(f[p],e[i].w);
for(int i=head[p];~i;i=e[i].next)
if(e[i].v!=fa)ans+=f[p]-e[i].w;
for(int i=head[fa];i;i=e[i].next)
if(e[i].v==p)e[i].w+=f[p];
}
int main(void)
{
memset(head,-1,sizeof(head));
n=gi,s=gi;
for(int i=1;i<n;i++)
{
int u=gi,v=gi,w=gi;
add(u,v,w),add(v,u,w);
}
dfs(s,0);
printf("%lld\n",ans);
return 0;
}
我这里
CPPfor(int i=head[fa];i;i=e[i].next)
if(e[i].v==p)e[i].w+=f[p];
i没有写~i
居然没有T飞
这数据怕不是假的
chen_zhe
回复
共 1 条回复,欢迎继续交流。
正在加载回复...