QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#326616#8029. Traveling MerchantC1942huangjiaxuWA 26ms8388kbC++141.3kb2024-02-13 16:27:002024-02-13 16:27:00

Judging History

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

  • [2024-08-07 20:25:21]
  • hack成功,自动添加数据
  • (/hack/771)
  • [2024-02-13 16:27:00]
  • 评测
  • 测评结果:WA
  • 用时:26ms
  • 内存:8388kb
  • [2024-02-13 16:27:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int T,n,m,dfn[N],dp[N],low[N],st[N],tp,fa[N][18],up[N];
char c[N];
vector<int>e[N];
vector<pair<int,int> >E;
int lca(int x,int y){
	if(dp[x]<dp[y])swap(x,y);
	for(int i=17;~i;--i)if(dp[fa[x][i]]>=dp[y])x=fa[x][i];
	if(x==y)return x;
	for(int i=17;~i;--i)if(fa[x][i]!=fa[y][i])x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}
void tarjan(int x){
	dfn[x]=low[x]=++dfn[0],st[++tp]=x,up[x]=dp[x]=dp[fa[x][0]]+1;
	for(int i=1;i<18;++i)fa[x][i]=fa[fa[x][i-1]][i-1];
	for(auto v:e[x]){
		if(!dfn[v]){
			fa[v][0]=x;
			tarjan(v);
			low[x]=min(low[x],low[v]);
			if(low[v]<dfn[x])continue;
			if(st[tp]==v)--tp;
			else{
				do{
					up[st[tp--]]=dp[x];
				}while(st[tp+1]!=v);
			}
		}else low[x]=min(low[x],dfn[v]);
	}
}
void solve(){
	scanf("%d%d%s",&n,&m,c+1);
	for(int i=1;i<=n;++i)e[i].clear(),dfn[i]=low[i]=0;
	E.clear(),dfn[0]=tp=0;
	for(int i=1,x,y;i<=m;++i){
		scanf("%d%d",&x,&y);
		++x,++y;
		if(c[x]==c[y])E.emplace_back(x,y);
		else e[x].push_back(y),e[y].push_back(x);
	}
	tarjan(1);
	for(auto [x,y]:E)if(dfn[x]&&dfn[y]){
		int z=lca(x,y);
		if(z==x||z==y||up[x]<=dp[z]||up[y]<=dp[z])return puts("yes"),void();
	}
	puts("no");
}
int main(){
	scanf("%d",&T);
	while(T--)solve();
	return 0;
}

详细

Test #1:

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

input:

2
4 4
LHLH
0 1
1 2
1 3
2 3
3 3
LHH
0 1
0 2
1 2

output:

yes
no

result:

ok 2 lines

Test #2:

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

input:

12385
9 29
LHLLHLHLH
0 7
1 4
4 6
2 0
4 2
6 5
8 4
7 1
2 6
7 3
7 2
8 7
1 3
5 3
0 8
4 0
0 5
8 1
8 6
3 2
0 1
1 2
6 3
2 5
6 0
3 0
5 4
4 3
7 5
7 15
LLLLLHL
5 2
6 3
3 0
0 6
4 5
1 4
6 1
0 5
3 4
5 6
1 0
2 6
0 2
4 2
0 4
6 6
LHHHHH
5 0
0 4
2 5
1 4
1 3
3 4
9 8
LHLHLLHLL
5 7
5 4
7 4
7 8
1 5
0 1
1 8
1 2
5 4
LHHHH...

output:

yes
yes
no
no
no
yes
yes
yes
no
yes
yes
no
yes
yes
yes
yes
yes
yes
yes
yes
no
no
no
yes
no
no
yes
yes
no
no
yes
no
no
yes
yes
yes
yes
yes
yes
no
no
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
no
yes
yes
yes
yes
yes
yes
no
yes
yes
no
yes
yes
yes
yes
yes
yes
no
no
no
yes
yes
yes
no
yes
yes...

result:

wrong answer 280th lines differ - expected: 'no', found: 'yes'