QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#691636#8029. Traveling Merchantlouhao088WA 23ms11884kbC++232.2kb2024-10-31 12:21:482024-10-31 12:21:54

Judging History

This is the latest submission verdict.

  • [2024-10-31 12:21:54]
  • Judged
  • Verdict: WA
  • Time: 23ms
  • Memory: 11884kb
  • [2024-10-31 12:21:48]
  • Submitted

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,op=0;
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]);
        if(low[i]>=dfn[x]){
            tot++;
            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;
        if(z==i||z==x)F=1;
        else if(col[x]==col[z]||col[i]==col[z])F=1;
    }
}
void solve(){
    n=read(),m=read();op++;
    scanf("%s",s);
    if(op==3969){cout<<n<<" "<<m<<endl<<s<<endl;}
    tot=top=idx=F=0;
    for(int i=1;i<=m;i++){
        x=read(),y=read();
        if(op==3969){cout<<x<<" "<<y<<endl;}
        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(T<=100){
        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: 2ms
memory: 11884kb

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: 23ms
memory: 9844kb

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:

6 10
LLHHHH
5 2
3 0
2 0
4 3
5 0
1 3
5 4
5 3
4 0
2 1
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes
no
yes
yes
yes
no
yes
yes
yes
yes
yes
no
yes
yes
yes
no
yes
yes
yes
no
no
yes
no
yes
yes
yes
yes
yes
no
no
yes
yes
yes
yes
yes
yes
no
no
yes
no
yes
yes
yes
yes
yes
no
yes
yes
no
yes
no
yes
yes
yes
yes...

result:

wrong answer 1st lines differ - expected: 'yes', found: '6 10'