QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#697426#8055. BalanceGreen_HandWA 26ms14072kbC++203.7kb2024-11-01 14:02:312024-11-01 14:02:31

Judging History

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

  • [2024-11-01 14:02:31]
  • 评测
  • 测评结果:WA
  • 用时:26ms
  • 内存:14072kb
  • [2024-11-01 14:02:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 1E5 + 7;
int n,m,num,T,a[N],b[2][N];

void read(int &x)
{
	char c = getchar(); x = 0;
	while(c < '0' || c > '9') c = getchar();
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
}

struct Tree
{
	int tot,flag,val[N],siz[N],st[N],col[N],f[N][2],id[N][2],to[N << 1],nxt[N << 1],tag[N << 1];
	
	void init()
	{
		tot = 1, flag = 0;
		for(int i = 1;i <= n + 1; ++ i) st[i] = val[i] = col[i] = 0;
	}
	
	void add(int u,int v)
	{ to[++tot] = v, nxt[tot] = st[u], st[u] = tot, tag[tot] = 1; }
	
	void add_edge(int u,int v) { add(u,v), add(v,u); }
	
	void dfs(int x,int fa)
	{
		if(flag) return;
		
		f[x][0] = 0, f[x][1] = num + 1,
		id[x][0] = id[x][1] = 0, siz[x] = val[x];
		
		for(int i = st[x],v,t1,t2;i;i = nxt[i])
			if((v = to[i]) != fa)
			{
				dfs(v,x), siz[x] += siz[v];
				
				t1 = f[v][0] + (siz[v] == b[0][f[v][0] + 1]);
				if(t1 + 1 == f[x][1])
				{
					flag = 1, f[x][0] = t1, id[x][0] = i,
					solve(x,0), solve(x,1), col[x] = f[x][1], cover(x);
					return;
				}
				
				t2 = f[v][1] - (siz[v] == b[1][f[v][1] - 1]);
				if(f[x][0] + 1 == t2)
				{
					flag = 1, f[x][1] = t2, id[x][1] = i,
					solve(x,0), solve(x,1), col[x] = f[x][1], cover(x);
					return;
				}
				
				if(t1 > f[x][0]) f[x][0] = t1, id[x][0] = i;
				if(t2 < f[x][1]) f[x][1] = t2, id[x][1] = i;
			}
	}
	
	void solve(int x,int type)
	{
		if(id[x][type])
		{
			int v = to[id[x][type]];
			solve(v,type);
			if(f[x][type] != f[v][type])
				tag[id[x][type]] = tag[id[x][type] ^ 1] = 0,
				col[v] = f[type ? v : x][type], cover(v);
		}
	}
	
	void cover(int x)
	{
		for(int i = st[x],v;i;i = nxt[i])
			if(tag[i] && !col[v = to[i]]) col[v] = col[x], cover(v);
	}
	
} t;

struct Graph
{
	int tot,top,cnt,s[N],st[N],dfn[N],col[N],low[N],to[N << 2],nxt[N << 2];
	
	void init()
	{
		tot = 1, top = cnt = 0;
		for(int i = 1;i <= n + 1; ++ i) st[i] = dfn[i] = s[i] = 0;
	}
	
	void add(int u,int v)
	{ to[++tot] = v, nxt[tot] = st[u], st[u] = tot; }
	
	void tarjan(int x,int lst)
	{
		s[++top] = x, low[x] = dfn[x] = ++cnt;
		
		for(int i = st[x],v;i;i = nxt[i])
			if(i != (lst ^ 1))
			{
				if(!dfn[v = to[i]])
					tarjan(v,i), low[x] = min(low[x],low[v]);
				else
					low[x] = min(low[x],dfn[v]);
			}
		
		if(dfn[x] == low[x])
			while(s[top + 1] != x) col[s[top--]] = x, ++t.val[x];
	}
	
	void update()
	{
		for(int x = 1;x <= n; ++ x)
			for(int i = st[x],v;i;i = nxt[i])
				if(col[x] < col[v = to[i]]) t.add_edge(col[x],col[v]);
	}
	
} g;

int main()
{
	int tmp = 1;
	for(read(T);tmp <= T; ++tmp)
	{
		read(n), read(m), g.init(), t.init(), num = 0;
		if(T == 100000 && tmp == 38) printf("n = %d, m = %d\n",n,m);
		for(int i = 1,u,v;i <= m; ++ i)
			read(u), read(v), g.add(u,v), g.add(v,u),
			T == 100000 && tmp == 38 && (printf("%d %d\n",u,v), 1);
		
		for(int i = 1;i <= n; ++ i) read(a[i]), T == 100000 && tmp == 38 && (printf("%d ",a[i]));
		if(T == 100000 && tmp == 38) putchar('\n');
		sort(a + 1,a + n + 1);
		for(int i = 1;i < n; ++ i)
			if(a[i] != a[i + 1]) b[0][++num] = i, b[1][num] = n - b[0][num];
		b[0][num + 1] = b[1][0] = n, b[0][0] = b[1][num + 1] = 0;
		
		if((T < 100000 || (T == 100000 && tmp == 38)) && !num)
		{
			printf("Yes\n");
			for(int i = 1;i <= n; ++ i)
				printf("%d%c",a[i]," \n"[i == n]);
			continue;
		}
		
		g.tarjan(1,0), g.update(), t.dfs(g.col[1],0);
		if(T < 100000 || (T == 100000 && tmp == 38))
		{
			if(!t.flag) { printf("No\n"); continue; }
			printf("Yes\n");
			for(int i = 1,x;i <= n; ++ i)
				x = t.col[g.col[i]],
				printf("%d%c",x == num + 1 ? a[n] : a[b[0][x]]," \n"[i == n]);
		}
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 14044kb

input:

5
5 4
1 2
2 3
3 4
4 5
1 2 3 4 5
5 4
1 2
1 3
1 4
1 5
1 2 3 4 5
5 4
1 2
1 3
1 4
1 5
1 2 2 2 3
5 6
1 2
1 2
2 3
3 4
4 5
3 5
1 2 1 2 1
2 2
1 2
1 2
1 2

output:

Yes
5 4 3 2 1
No
Yes
2 3 1 2 2
Yes
2 2 1 1 1
No

result:

ok ok (5 test cases)

Test #2:

score: -100
Wrong Answer
time: 26ms
memory: 14072kb

input:

100000
4 3
4 2
1 3
2 1
2 1 3 2
5 7
2 5
5 3
2 3
5 1
4 3
2 4
4 3
1 3 1 1 2
3 2
2 1
2 3
1 1 1
4 7
3 4
1 4
2 3
4 3
4 2
3 1
4 3
2 3 3 2
4 6
2 4
3 1
1 2
1 2
2 3
4 2
1 1 3 3
4 7
3 2
4 2
1 2
3 4
3 2
2 4
3 4
2 1 1 1
5 5
3 2
1 5
4 5
4 3
2 1
1 2 2 3 2
3 5
2 3
1 3
3 1
3 1
2 1
3 2 3
2 3
2 1
2 1
1 2
1 1
2 3
2 1
1...

output:

n = 4, m = 3
3 4
1 3
4 2
2 1 1 1 
Yes
2 2 1 1

result:

wrong answer Token parameter [name=yesno] equals to "n", doesn't correspond to pattern "Yes|No" (test case 1)