QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#23021#2543. Edges, Colors and MSTforeverlasting#WA 4ms24196kbC++203.2kb2022-03-11 15:57:072022-04-30 02:13:38

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 02:13:38]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:24196kb
  • [2022-03-11 15:57:07]
  • 提交

answer

#include<bits/stdc++.h>
#define pii pair<int,int>
#define fr first
#define sc second
#define mp make_pair
using namespace std;
#define RG 
#define LL long long
#define gc getchar
#define pb push_back
const int mxn=1e6+10;
int n,m,ex[mxn],pos[mxn],ans[mxn];
int tim,fa[mxn],dep[mxn],siz[mxn],son[mxn],dfn[mxn],top[mxn];
int t,h[mxn];
struct Tre
{
	int to,nxt;
}e[mxn<<1];
struct Edge
{
	int x,y,z;
}a[mxn];
struct Seg_tree
{
	int v,mn,tg;
}tr[mxn<<2];
pii c[mxn];
inline int rd(){
	int s=0,w=1,ch=gc();
	while(ch<'0'||ch>'9'){
		if(ch=='-')w=-1;
		ch=gc();
	}
	while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
	return s*w;
}
void add(int u,int v)
{
	e[++t]=(Tre){v,h[u]};h[u]=t;
	e[++t]=(Tre){u,h[v]};h[v]=t;
}
void dfs1(int u)
{
	int v;siz[u]=1;
	for(int i=h[u];i;i=e[i].nxt)
		if((v=e[i].to)!=fa[u])
		{
			fa[v]=u;dep[v]=dep[u]+1;
			dfs1(v);siz[u]+=siz[v];
			if(siz[v]>siz[son[u]]) son[u]=v;
		}
}
void dfs2(int u,int tp)
{
	top[u]=tp;dfn[u]=++tim;
	if(son[u]) dfs2(son[u],tp);
	int v;
	for(int i=h[u];i;i=e[i].nxt)
		if((v=e[i].to)!=fa[u]&&v!=son[u])
			dfs2(v,v);
}
#define mid ((l+r)>>1)
void chg(int x,int v) {tr[x].v=0; tr[x].mn=min(tr[x].mn,v); tr[x].tg=v;}
void pushdown(int x)
{
	if(tr[x].tg)
	{
		chg(x<<1,tr[x].tg);chg(x<<1|1,tr[x].tg);
		tr[x].tg=0;
	}
}
void build(int x,int l,int r)
{
	tr[x].v=r-l+1;tr[x].mn=m+1;
	if(l==r) return ;
	build(x<<1,l,mid);build(x<<1|1,mid+1,r);
}
void update(int x,int l,int r,int L,int R,int v)
{
	if(L<=l&&r<=R) return chg(x,v);
	pushdown(x);
	if(L<=mid) update(x<<1,l,mid,L,R,v);
	if(R>mid) update(x<<1|1,mid+1,r,L,R,v);
	tr[x].v=tr[x<<1].v+tr[x<<1|1].v;
}
int query(int x,int l,int r,int L,int R)
{
	if(L<=l&&r<=R) return tr[x].v;
	int res=0;
	pushdown(x);
	if(L<=mid) res=query(x<<1,l,mid,L,R);
	if(R>mid) res+=query(x<<1|1,mid+1,r,L,R);
	return res;
}
void prework(int x,int l,int r)
{
	if(l==r) return (void)(c[l]=mp(tr[x].mn,pos[l]));
	prework(x<<1,l,mid);prework(x<<1|1,mid+1,r);
}
#undef mid
void upd(int u,int v,int w)
{
	for(;top[u]!=top[v];u=fa[top[u]])
	{
		if(dep[top[u]]<dep[top[v]]) swap(u,v);
		update(1,1,n,dfn[top[u]],dfn[u],w);
	}
	if(dep[u]>dep[v]) swap(u,v);
	if(u^v) update(1,1,n,dfn[u]+1,dfn[v],w);
}
int qry(int u,int v)
{
	int res=0;
	for(;top[u]!=top[v];u=fa[top[u]])
	{
		if(dep[top[u]]<dep[top[v]]) swap(u,v);
		res+=query(1,1,n,dfn[top[u]],dfn[u]);
	}
	if(dep[u]>dep[v]) swap(u,v);
	if(u^v) res+=query(1,1,n,dfn[u]+1,dfn[v]);
	return res;
}
int main()
{
	n=rd();m=rd();
	for(int x,y,z,i=1;i<=m;++i)
	{
		x=rd();y=rd();z=rd();
		a[i]=(Edge){x,y,z};
		if(z&1) add(x,y);
	}
	dfs1(1);dfs2(1,1);build(1,1,n);
	int cnt=0;
	for(int x,i=1;i<=m;++i)
		if(a[i].z)
		{
			x=max(dfn[a[i].x],dfn[a[i].y]);pos[x]=i;
//			if(query(1,1,n,x,x)) ex[ans[i]=++cnt]=1,update(1,1,n,x,x,cnt);
		}
		else
		{
			x=qry(a[i].x,a[i].y);upd(a[i].x,a[i].y,cnt+=x);
			ex[ans[i]=++cnt]=1;
		}
	prework(1,1,n);
	sort(c+2,c+n+1);
	for(int nw=0,i=2;i<=n;++i)
		if(!ans[c[i].sc])
		{
			for(++nw;ex[nw];++nw);
			ans[c[i].sc]=nw;
		}
	for(int i=1;i<=m;++i) printf("%d%c",ans[i]," \n"[i==m]);
	return 0;
}
/*
4 5
1 2 0
2 3 1
3 4 1
2 4 0
1 3 1
*/

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 24076kb

input:

4 5
1 2 0
2 3 1
3 4 1
2 4 0
1 3 1

output:

3 1 4 5 2

result:

ok 5 number(s): "3 1 4 5 2"

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 24196kb

input:

9 15
1 4 1
3 5 1
3 9 0
1 3 0
2 5 0
5 8 0
6 9 0
8 9 0
1 7 1
1 8 1
6 8 1
4 9 1
2 4 1
3 4 1
4 6 0

output:

4 6 3 5 8 10 12 13 15 9 11 1 7 2 14

result:

wrong answer 1st numbers differ - expected: '1', found: '4'