QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#629625#8029. Traveling Merchantucup-team3161#WA 31ms81432kbC++141.2kb2024-10-11 13:53:502024-10-11 13:53:51

Judging History

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

  • [2024-10-11 13:53:51]
  • 评测
  • 测评结果:WA
  • 用时:31ms
  • 内存:81432kb
  • [2024-10-11 13:53:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
const int N=1e6+5;
int T,n,n1,m,dfn[N],low[N],st[N],fa[N],dfnl[N],dfnr[N];char a[N];
vector<int> e[N],e1[N],e2[N];
void add(int u,int v) {e2[u].eb(v);e2[v].eb(u);}
void Tarjan(int u,int f)
{
	dfn[u]=low[u]=++dfn[0];st[++st[0]]=u;
	for(auto v:e[u]) if(v!=f)
	{
		if(!dfn[v])
		{
			Tarjan(v,u);low[u]=min(low[u],low[v]);
			if(low[v]>=dfn[u])
			{
				add(++n1,u);add(n1,v);
				while(st[st[0]]!=v) add(n1,st[st[0]--]);--st[0];
			}
		}
		else low[u]=min(low[u],dfn[v]);
	}
}
void dfs(int u,int f)
{
	dfnl[u]=++dfnl[0];fa[u]=f;
	for(auto v:e2[u]) if(v!=f) dfs(v,u);dfnr[u]=dfnl[0];
}
void slv()
{
	scanf("%d %d %s",&n,&m,a+1);dfnl[0]=0;fill(dfn,dfn+n+1,0);
	for(int i=1;i<=n1;++i)
		e[i].clear(),e1[i].clear(),e2[i].clear();n1=n;
	for(int i=1,u,v;i<=m;++i)
	{
		scanf("%d %d",&u,&v);++u;++v;
		if(a[u]==a[v]) e1[u].eb(v),e1[v].eb(u);
		else e[u].eb(v),e[v].eb(u);
	}
	Tarjan(1,0);dfs(1,0);
	for(int i=1;i<=n;++i) if(dfn[i]) for(auto j:e1[i]) if(dfn[j])
		if(fa[i]==fa[j] || (dfnl[i]>=dfnl[j] && dfnr[i]<=dfnr[j]))
		{puts("yes");return;}
	puts("no");
}
int main()
{
	scanf("%d",&T);
	while(T--) slv();return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 81432kb

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: 31ms
memory: 74648kb

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 568th lines differ - expected: 'yes', found: 'no'