QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#691629 | #8029. Traveling Merchant | louhao088 | WA | 24ms | 11844kb | C++23 | 2.3kb | 2024-10-31 12:18:44 | 2024-10-31 12:18:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define lowbit(i) (i&(-i))
const int mod=1e9+7,maxn=2e5+5,M=100005;
#define pb push_back
inline int read(){
char ch=getchar();int x=0;bool f=0;
for(;!isdigit(ch);ch=getchar())if(ch=='-')f=1;
for(;isdigit(ch);ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
if(f==1)x=-x;return x;
}
int n,m,x,y,a[maxn],Rt,T,f[maxn][22],dep[maxn],vis[maxn];
char s[maxn];
int st[maxn],dfn[maxn],low[maxn],tot,idx,top,F;
vector<int>e[maxn],g[maxn];
int col[maxn],id[maxn];
int Lca(int x,int y){
if(dep[x]<dep[y])swap(x,y);
for(int i=20;i>=0;i--)if(dep[f[x][i]]>=dep[y])x=f[x][i];
if(x==y)return x;
for(int i=20;i>=0;i--)if(f[x][i]!=f[y][i])x=f[x][i],y=f[y][i];
return f[x][0];
}
void tarjan(int x,int fa){
dfn[x]=low[x]=++idx;st[++top]=x;
f[x][0]=fa;dep[x]=dep[fa]+1;
for(auto i:e[x]){
if(dfn[i]){
low[x]=min(low[x],dfn[i]);
continue;
}tarjan(i,x);
low[x]=min(low[x],low[i]);
//cout<<low[x]<<" "<<low[i]<<" "<<x<<" "<<i<<endl;
if(low[i]>=dfn[x]){
tot++;
//cout<<st[top]<<" "<<tot<<" "<<top<<endl;
while(st[top+1]!=i){col[st[top]]=tot;top--;}
}
}
}
void dfs(int x,int fa){
vis[x]=1;
for(auto i:e[x])if(!vis[i]){
dfs(i,x);
}
for(auto i:g[x]){
int z=Lca(i,x);
if(!dfn[i]||!dfn[x])continue;
//cout<<z<<" "<<i<<" "<<x<<" "<<col[i]<<" "<<col[x]<<" "<<col[z]<<endl;
if(z==i||z==x)F=1;
else if(col[x]==col[z]||col[i]==col[z])F=1;
//else if(id[col[i]]==z||id[col[x]]==z)F=1;
}
}
void solve(){
n=read(),m=read();
scanf("%s",s);
tot=top=idx=F=0;
for(int i=1;i<=m;i++){
x=read(),y=read();
if(s[x]!=s[y])e[x].pb(y),e[y].pb(x);
else g[x].pb(y),g[y].pb(x);
}
tarjan(0,0);
//cout<<top<<endl;
for(int j=1;j<=20;j++)
for(int i=0;i<n;i++)
f[i][j]=f[f[i][j-1]][j-1];
dfs(0,0);
if(F)puts("yes");
else puts("no");
for(int i=0;i<n;i++)e[i].clear(),g[i].clear(),dfn[i]=vis[i]=low[i]=col[i]=id[i]=dep[i]=st[i]=0;
for(int i=0;i<n;i++)for(int j=0;j<=20;j++)f[i][j]=0;
}
int main() {
T=read();
while(T--)solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9988kb
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: 24ms
memory: 11844kb
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 3969th lines differ - expected: 'no', found: 'yes'