QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#230644#7640. Colorful Cyclesucup-team2303#WA 238ms92884kbC++144.0kb2023-10-28 20:01:572023-10-28 20:01:57

Judging History

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

  • [2024-07-04 22:58:32]
  • hack成功,自动添加数据
  • (/hack/728)
  • [2023-10-28 20:01:57]
  • 评测
  • 测评结果:WA
  • 用时:238ms
  • 内存:92884kb
  • [2023-10-28 20:01:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
mt19937_64 rnd(time(0));
long long T,a,b,c,d[1000001],v[1000001],o,h[1000001],fa[1000001],q,w,e,an,cn,u[1000001],dfn[1000001],low[1000001],cnt=0,de[1000001],stt[1000001],cnn,vi[1000001];
struct p{long long q,w,e;}l[2000001],m[2000001];
inline int read(){int x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}return x*f;}
void add(long long qq,long long ww,long long ee){l[++o].q=ww,l[o].w=h[qq],l[o].e=ee,h[qq]=o;}
long long find(long long qq){return qq==fa[qq]?qq:fa[qq]=find(fa[qq]);}
void merge(long long qq,long long ww){long long f1=find(qq),f2=find(ww);if(f1==f2) return;fa[f1]=f2;}
bool cmp(p qq,p ww){if(qq.q==ww.q&&qq.w==ww.w) return qq.e<ww.e;if(qq.q==ww.q) return qq.w<ww.w;return qq.q<ww.q;}
vector<p> qu[1000001];
void add1(long long qq,long long ww,long long ee,long long rr){qu[qq].push_back(p{ww,ee,rr});}
struct pp{long long q;p w;}st[1000001];
vector<vector<pp>> quu;
void dfs(long long qq,long long ww)
{
	dfn[qq]=low[qq]=++cnt;
	for(int i=0;i<qu[qq].size();i++)
	{
		if(qu[qq][i].w!=ww)
		{
			if(!dfn[qu[qq][i].q])
			{
				st[++cn]=pp{qq,qu[qq][i]};
				dfs(qu[qq][i].q,qu[qq][i].w);
				low[qq]=min(low[qq],low[qu[qq][i].q]);
				if(low[qu[qq][i].q]>=dfn[qq])
				{
					vector<pp> tmp;tmp.clear();
					while(st[cn].w.e!=qu[qq][i].e)
					{
						tmp.push_back(st[cn]);
						--cn;
					}tmp.push_back(st[cn]);--cn;
					quu.push_back(tmp);
				}
			}
			else st[++cn]=pp{qq,qu[qq][i]},low[qq]=min(low[qq],dfn[qu[qq][i].q]);
		}
	}
}
queue<long long> qu1;
map<long long,long long> ve[1000001];
int main()
{
	scanf("%lld",&T);
	for(int ii=1;ii<=T;ii++)
	{
		scanf("%lld%lld",&a,&b);
		for(int i=1;i<=a;i++) qu[i].clear();cnt=cn=0;
		for(int i=1;i<=b;i++)
		{
			scanf("%lld%lld%lld",&q,&w,&e);
			if(q>w) swap(q,w);
			m[i]=p{q,w,(1<<(e-1))};
		}
		sort(m+1,m+b+1,cmp);
		long long nn=0;
		for(int i=1;i<=b;i++)
		{
			if(m[i].q!=m[i-1].q||m[i].w!=m[i-1].w||m[i].e!=m[i-1].e) m[++nn]=m[i];
		}b=nn;
		for(int i=1;i<=b;i++)
		{
			add1(m[i].q,m[i].w,m[i].e,i);add1(m[i].w,m[i].q,m[i].e,i);
		}
		for(int i=1;i<=a;i++) dfn[i]=low[i]=0;cn=0;quu.clear();
		for(int i=1;i<=a;i++) if(!dfn[i]) dfs(i,0);
		bool fl1=0;
		for(int i=0;i<quu.size();i++)
		{
			o=0;for(int j=0;j<quu[i].size();j++) qu[quu[i][j].q].clear(),qu[quu[i][j].w.q].clear();
			nn=0;long long lm=0;
			for(int j=0;j<quu[i].size();j++) m[++nn]=p{quu[i][j].q,quu[i][j].w.q,quu[i][j].w.w};
			sort(m+1,m+nn+1,cmp);
			for(int j=1;j<=nn;j++)
			{
				if(m[j].q!=m[j-1].q||m[j].w!=m[j-1].w||m[j].e!=m[j-1].e) m[++lm]=m[j];
			}nn=lm;
			for(int j=1;j<=nn;j++) de[m[j].q]=de[m[j].w]=0;
			for(int j=1;j<=nn;j++) add1(m[j].q,m[j].w,m[j].e,j),add1(m[j].w,m[j].q,m[j].e,j),de[m[j].q]++,de[m[j].w]++,vi[j]=0;
			long long rt=quu[i][0].q,fl=1;
			for(int j=1;j<=nn;j++) if(de[m[j].q]==1||de[m[j].w]==1) fl=0;
			if(!fl) continue;cnn=0;
			for(int j=1;j<=nn;j++) stt[++cnn]=m[j].q,stt[++cnn]=m[j].w;
			sort(stt+1,stt+cnn+1);cnn=unique(stt+1,stt+cnn+1)-stt-1;
			while(!qu1.empty()) qu1.pop();
			for(int j=1;j<=cnn;j++) ve[stt[j]].clear();
			for(int j=1;j<=cnn;j++) if(de[stt[j]]==2) qu1.push(stt[j]);
			bool fll=0;
			while(!qu1.empty())
			{
				long long r=qu1.front();qu1.pop();
				p w1,w2;w1.q=0,w2.q=0;
				for(int j=0;j<qu[r].size();j++)
				{
					if(!vi[qu[r][j].e])
					{
						vi[qu[r][j].e]=1;
						if(!w1.q) w1=qu[r][j];
						else if(!w2.q) w2=qu[r][j];
						de[r]--,de[qu[r][j].q]--;
					}
				}
				if(!w2.q) continue;
				w1.w|=w2.w;
				if((ve[w1.q][w2.q]|w1.w)==7)
				{
					fll=1;break;
				}
				de[w1.q]--,de[w2.q]--;
				if(ve[w1.q][w2.q]!=w1.w)
				{
					de[w1.q]++,de[w2.q]++;
					ve[w1.q][w2.q]|=w1.w;
					++nn;vi[nn]=0;
					qu[w1.q].push_back(p{w2.q,w1.w,nn});
					qu[w2.q].push_back(p{w1.q,w1.w,nn});
				}
			}
			if(fll)
			{
				fl1=1;break;
			}
		}
		if(fl1) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 9ms
memory: 92884kb

input:

2
3 3
1 2 3
2 3 1
1 3 2
5 6
1 2 1
2 3 1
1 3 2
3 4 3
3 5 3
4 5 3

output:

Yes
No

result:

ok 2 token(s): yes count is 1, no count is 1

Test #2:

score: -100
Wrong Answer
time: 238ms
memory: 91396kb

input:

100000
7 10
7 2 2
6 4 2
6 1 2
7 1 3
3 4 1
6 7 1
2 6 3
3 1 2
5 3 1
2 1 1
7 10
5 7 3
7 1 1
4 6 3
6 3 1
3 4 3
4 2 2
3 2 3
1 3 3
3 7 1
1 4 2
7 10
5 6 3
3 5 2
7 2 3
7 3 3
1 2 2
4 3 2
7 4 2
6 1 2
2 6 1
7 5 2
7 10
7 1 3
7 5 3
6 4 1
7 6 1
1 4 1
3 4 2
2 7 2
1 3 1
3 5 3
5 1 3
7 10
6 7 2
3 4 3
1 4 2
5 3 2
7 4 ...

output:

No
Yes
No
No
No
No
Yes
No
No
No
Yes
Yes
No
No
Yes
No
No
Yes
No
Yes
Yes
No
No
No
No
No
No
No
No
No
Yes
No
No
No
No
Yes
Yes
No
Yes
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
Yes
No
No
No
Yes
Yes
No
No
No
No
Yes
No
Yes
No
No
Yes
Yes
Yes
No
No
No
No
No
No
Yes
No
No
No
Yes
No
No
No
No
Yes
No
No
No
No
...

result:

wrong answer expected YES, found NO [1st token]