QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#230689 | #7640. Colorful Cycles | ucup-team2303# | WA | 327ms | 92376kb | C++14 | 4.0kb | 2023-10-28 20:18:43 | 2023-10-28 20:18:44 |
Judging History
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],q,w,e,an,cn,u[1000001],dfn[1000001],low[1000001],cnt=0,de[1000001],stt[1000001],cnn,vi[1000001],vv[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;}
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++)
{
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;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;
for(int j=1;j<=cnn;j++) de[stt[j]]=0,qu[stt[j]].clear();
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;
while(!qu1.empty()) qu1.pop();
for(int j=1;j<=cnn;j++) ve[stt[j]].clear(),vv[stt[j]]=0;
for(int j=1;j<=cnn;j++) if(de[stt[j]]<=2) qu1.push(stt[j]),vv[stt[j]]=1;
for(int j=1;j<=nn;j++) ve[m[j].q][m[j].w]|=m[j].e,ve[m[j].w][m[j].q]|=m[j].e;
bool fll=0;
for(int j=1;j<=nn;j++) if(ve[m[j].q][m[j].w]==7) fll=1;
while(!qu1.empty())
{
if(fll) break;
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)
{
de[w1.q]--;
if(de[w1.q]<=2&&!vv[w1.q]) qu1.push(w1.q),vv[w1.q]=1;
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,ve[w2.q][w1.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(de[w1.q]<=2&&!vv[w1.q]) qu1.push(w1.q),vv[w1.q]=1;
if(de[w2.q]<=2&&!vv[w2.q]) qu1.push(w2.q),vv[w2.q]=1;
}
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: 4ms
memory: 91768kb
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: 327ms
memory: 92376kb
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:
Yes Yes No No Yes Yes Yes No Yes No Yes Yes No No Yes Yes Yes Yes No Yes Yes Yes No Yes No No Yes Yes No Yes Yes Yes Yes Yes No Yes Yes No Yes No No No Yes Yes Yes No No No Yes Yes No No No Yes Yes Yes Yes Yes Yes Yes No No Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes Yes Yes No Yes Yes Yes Yes No No ...
result:
wrong answer expected YES, found NO [3rd token]