QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#227700 | #7640. Colorful Cycles | ucup-team1447# | Compile Error | / | / | C++14 | 4.9kb | 2023-10-27 21:26:59 | 2023-10-27 21:26:59 |
Judging History
你现在查看的是最新测评结果
- [2024-07-04 22:58:32]
- hack成功,自动添加数据
- (/hack/728)
- [2023-10-27 21:26:59]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-10-27 21:26:59]
- 提交
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define ull unsigned long long
//#define int long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 2000005
#define inf 0x3f3f3f3f
int n,m;
int uu[maxn],vv[maxn],ww[maxn];
bool don[maxn];
vector<pii>e[maxn];
vi g[maxn];
pii ban[maxn];
int fa[maxn][21],w[maxn][21];
int dsu[maxn];
int gf(int x){
while(x!=dsu[x])x=dsu[x]=dsu[dsu[x]];
return x;
}
struct ttmp{
vi o,s;
int n;
int sta;
int id(int u){return lower_bound(o.begin(),o.end(),u)-o.begin()+1;}
pii ban;
void init1(vi t,int u){
o=t; o.pb(u); sort(o.begin(),o.end());
n=o.size(); s.resize(n+1);
sta=0; For(i,0,n) s[i]=0; ban=mkp(0,0);
}
void adde(int u,int v,int w){
if(!n)return;
u=id(u),v=id(v);
// cout<<"adde "<<u<<" "<<v<<" "<<w<<' '<<n<<endl;
if(w<=1) s[u]|=(1<<w),s[v]|=(1<<w),sta|=(1<<w);
}
void init2(){
if(sta!=3) return;
ban=mkp(0,0);
// For(i,1,n)cout<<s[i]<<" "; puts("");
vi vec;
For(i,1,n){
if(s[i]==3)vec.pb(i);
if(vec.size()>2)return;
}
assert(vec.size()==2);
ban=mkp(o[vec[0]-1],o[vec[1]-1]);
}
int ask(int u,int v){
if(sta!=3) return (1<<sta);
if(ban!=mkp(0,0)) {
if(u==ban.fi && v==ban.se) return (1<<1)|(1<<2);
if(u==ban.se && v==ban.fi) return (1<<1)|(1<<2);
}
return (1<<3);
}
}t[maxn];
int F[25][25];
int dfn[maxn],low[maxn],stk[maxn],tp,cnt,idx,bel[maxn];
void tar(int u,int pa)
{
dfn[u]=low[u]=++idx,stk[++tp]=u;
for(auto it:e[u]){
int v=it.fi,w=it.se;
if(v==pa)continue;
if(!dfn[v]){
tar(v,u);
low[u]=min(low[u],low[v]);
if(low[v]>=dfn[u]){
++cnt; int x;
g[u].pb(cnt); fa[cnt][0]=u;// cout<<"addg "<<u<<' '<<cnt<<endl;
fa[cnt][0]=u;
do{
x=stk[tp--];
g[cnt].pb(x),bel[x]=cnt; //cout<<"addg "<<cnt<<" "<<x<<endl;
fa[x][0]=cnt;
}while(x!=v);
}
}
else low[u]=min(low[u],dfn[v]);
}
}
int dep[maxn];
void dfs(int u,int pa){
// cout<<"dfs "<<u<<" "<<pa<<endl;
dep[u]=dep[pa]+1,fa[u][0]=pa;
if(1<u&&u<=n) w[u][0]=t[pa].ask(u,fa[pa][0]);
else w[u][0]=1;
// cout<<"u: "<<u<<" "<<pa<<" "<<w[u][0]<<"\n";
// cout<<"DFS "<<u<<" "<<pa<<endl;
For(i,1,20){
fa[u][i]=fa[fa[u][i-1]][i-1];
if(fa[u][i]) w[u][i]=F[w[u][i-1]][w[fa[u][i-1]][i-1]];
}
for(auto v:g[u]) dfs(v,u);
}
int query(int u,int v){
if(dep[u]<dep[v])swap(u,v);
int res=1;
// while(dep[u]>dep[v])res+=w[u][0]cout<<"ADD0 "<<u<<' '<<w[u][0].x.x<<" "<<w[u][0].y.x<<endl,u=fa[u][0];
Rep(i,20,0)
if(dep[fa[u][i]]>=dep[v]){
res=F[res][w[u][i]];
u=fa[u][i];
}
if(u==v)return (res>>3&1);
Rep(i,20,0)
if(fa[u][i]!=fa[v][i]){
res=F[res][w[u][i]];
res=F[res][w[v][i]];
u=fa[u][i],v=fa[v][i];
}
if(fa[u][0]>n)res=F[res][t[fa[u][0]].ask(u,v)];
// cout<<"res: "<<res.x.x<<' '<<res.y.x<<endl;
return (res>>3&1);
}
void work()
{
n=read(),m=read();
For(i,1,n*2){
e[i].clear(),g[i].clear(),dfn[i]=low[i]=stk[i]=don[i]=bel[i]=dep[i]=0;
For(j,0,20) w[u][j]=fa[u][j]=0;
}
tp=idx=0;
For(i,1,n)dsu[i]=i;
auto adds=[&](int u,int v,int w){
// cout<<"add "<<u<<" "<<v<<" "<<w<<"\n";
e[u].pb(mkp(v,w));
e[v].pb(mkp(u,w));
dsu[gf(u)]=gf(v);
};
For(i,1,m){
uu[i]=read(),vv[i]=read(),ww[i]=read()-1;
if(ww[i]<=1){
adds(uu[i],vv[i],ww[i]);
}
}
For(i,1,m){
if(ww[i]==2){
int u=uu[i],v=vv[i],w=ww[i];
if(gf(u)!=gf(v)){
adds(uu[i],vv[i],ww[i]);
}
}
}
cnt=n; tar(1,0);
// puts("qaq");
For(i,n+1,cnt) t[i].init1(g[i],fa[i][0]);
For(u,1,n)
for(auto it:e[u]){
int v=it.fi,w=it.se;
// cout<<"edge "<<u<<" "<<v<<" "<<w<<"\n";
if(fa[v][0]==fa[u][0]) t[fa[u][0]].adde(u,v,w);
if(fa[fa[v][0]][0]==u) t[fa[v][0]].adde(u,v,w);
if(fa[fa[u][0]][0]==v) t[fa[u][0]].adde(u,v,w);
}
// puts("qwq");
For(i,n+1,cnt) t[i].init2();
// puts("qwqwq");
dfs(1,0);
For(i,1,m){
if(ww[i]==2){
int t=query(uu[i],vv[i]);
if(t){
puts("Yes");
return;
}
}
}
puts("No");
}
signed main()
{
For(s,0,15)
For(t,0,15){
int ans=0;
For(i,0,3) For(j,0,3) if((s>>i&1) && (t>>j&1)) ans|=(1<<(i|j));
F[s][t]=ans;
}
// cout<<F[(1<<1)][(1<<2)]<<"\n";
int T=read();
while(T--)work();
return 0;
}
/*
1
7 9
1 3 1
3 2 1
1 4 2
4 2 2
1 5 3
5 6 3
5 7 3
7 6 2
6 2 3
4 4
1 2 1
2 3 2
3 4 3
1 4 1
5 6
1 2 1
2 3 1
1 3 2
3 4 3
3 5 3
4 5 1
*/
詳細信息
answer.code: In function ‘void work()’: answer.code:153:31: error: ‘u’ was not declared in this scope 153 | For(j,0,20) w[u][j]=fa[u][j]=0; | ^