QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#879892#9985. Exploration BoundarywcdrWA 7ms57160kbC++174.6kb2025-02-02 17:14:122025-02-02 17:14:22

Judging History

This is the latest submission verdict.

  • [2025-02-02 17:14:22]
  • Judged
  • Verdict: WA
  • Time: 7ms
  • Memory: 57160kb
  • [2025-02-02 17:14:12]
  • Submitted

answer

#include<random>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<ctime>
#include<cctype>
#include<cstdio>
#include<cstdlib>
#include<climits>
//#define NDEBUG
#include<cassert>
#include<cstring>
#include<complex>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<bitset>
//#define LL __int128
#define LL long long
#define ULL unsigned LL
#define uint unsigned int
//#define int LL
//#define double long double
#define mkp make_pair
#define par pair<int,int>
#define psb push_back
#define epb emplace_back
#define f(x) ((x).first)
#define s(x) ((x).second)
using namespace std;
#define Lbt(x) ((x)&(-(x)))
#define Swap(x,y) (x^=y^=x^=y)
const int Mxxx=1e5;
inline char gc()
{
//	return getchar();
	static char buf[Mxxx],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,Mxxx,stdin),p1==p2)?EOF:*p1++;
}
inline char pc(char ch,bool fl=false)
{
//	return fl?0:putchar(ch),0;
	static char buf[Mxxx],*p1=buf,*p2=buf+Mxxx;
	return (fl||((*p1++=ch)&&p1==p2))&&(fwrite(buf,1,p1-buf,stdout),p1=buf),0;
}
#define output pc('!',true)
inline int read()
{
	char ch=gc();
	int gans=0,gflag=0;
	for(;ch<'0'||'9'<ch;gflag|=ch=='-',ch=gc());
	for(;'0'<=ch&&ch<='9';gans=(gans<<1)+(gans<<3)+(ch^48),ch=gc());
	return gflag?-gans:gans;
}
template<typename T>
inline char read(T&gans)
{
	char ch=gc();
	int gflag=0;gans=0;
	for(;ch<'0'||'9'<ch;gflag|=ch=='-',ch=gc());
	for(;'0'<=ch&&ch<='9';gans=(gans<<1)+(gans<<3)+(ch^48),ch=gc());
	return gans=gflag?-gans:gans,ch;
}
template<typename T>
inline void write(T x)
{
	if(x>9)write(x/10);
	pc(x%10^48);
}
template<typename T>
inline void writenum(T x,char ch)
{
	if(x<0)pc('-'),x=-x;
	write(x);pc(ch);
}
inline void writechar(char x,char ch)
{
	pc(x);pc(ch);
}
template<typename T>
inline T Max(T x,T y)
{
	return x>y?x:y;
}
template<typename T>
inline T Min(T x,T y)
{
	return x<y?x:y;
}
template<typename T>
inline T Abs(T x)
{
	return x<0?-x:x;
}
template<typename T>
inline void ckmx(T&x,T y)
{
	x=Max(x,y);
}
template<typename T>
inline void ckmn(T&x,T y)
{
	x=Min(x,y);
}
namespace Tr
{
	const int Mx=1e6;
	int rt,cnt,lst;map<int,int>mp[Mx+5];
	int fl[Mx+5];
	inline int New()
	{
		int k=++cnt;
		fl[k]=0;mp[k].clear();
		return k;
	}
	inline void Clr()
	{
		cnt=0;rt=New();
	}
	inline void Pre()
	{
		lst=rt;
	}
	inline void Ins(int c)
	{
		if(mp[lst].find(c)==mp[lst].end())mp[lst][c]=New();
		lst=mp[lst][c];
	}
	inline void Tag()
	{
		fl[lst]=1;
	}
	inline int Chk(const set<int>&st)
	{
		if(st.empty())return 1;
		Pre();
		for(int c:st)
		{
			if(mp[lst].find(c)==mp[lst].end())return 0;
			lst=mp[lst][c];
		}
		return fl[lst];
	}
}
int TT;
const int Mx=2e5;
int n,m,cnt,h[Mx+5],nxt[(Mx<<1)+5],tto[(Mx<<1)+5];
inline void ade(int x,int y)
{
	nxt[++cnt]=h[x];
	tto[h[x]=cnt]=y;
}
inline void Ade(int x,int y)
{
	ade(x,y);ade(y,x);
}
int nm[Mx+5],vst[Mx+5];
set<int>st;queue<int>q;
inline void Ins(int x)
{
	if(vst[x])return;
	vst[x]=1;st.insert(x);
	if(!nm[x])q.push(x);
}
inline void Del(int x)
{
	assert(vst[x]);
	if(!(--nm[x]))q.push(x);
}
inline int Ept()
{
	return st.empty();
}
inline int Chk()
{
	return q.empty();
}
int num,ans[Mx+5];
inline void Pop()
{
	int i,x=q.front();q.pop();
	st.erase(x);ans[x]=++num;
	for(i=h[x];i;i=nxt[i])Ins(tto[i]);
}
int psx[Mx+5],psy[Mx+5];
int K,tt[Mx+5];vector<int>vec[Mx+5];
signed main()
{
	#ifndef ONLINE_JUDGE
	freopen("_.in","r",stdin);
//	freopen("_.out","w",stdout);
	#endif
	int i,j,f,x;
	for(TT=read();TT;TT--)
	{
		cerr<<TT<<"\n";
		n=read();m=read();
		num=cnt=0;for(i=1;i<=n;i++)h[i]=nm[i]=vst[i]=0;
		for(i=1;i<=m;i++)Ade(psx[i]=read(),psy[i]=read());
		K=read();Tr::Clr();
		for(i=1;i<=K;i++)
		{
			tt[i]=read();vec[i].clear();
			for(j=1;j<=tt[i];j++)vec[i].epb(read());
			sort(vec[i].begin(),vec[i].end());
			Tr::Pre();for(j=0;j<tt[i];j++)Tr::Ins(x=vec[i][j]),nm[x]++;
			Tr::Tag();
		}
		for(st.clear();!q.empty();q.pop());
		Ins(1);f=1;
		for(;!Ept();)
		{
			for(;!Chk();Pop());
			if(!Tr::Chk(st))
			{
				f=0;break;
			}
			for(int to:st)Del(to);
		}
		for(i=1;i<=n;i++)f&=(!nm[i]);
		if(f)
		{
			writechar('Y','e');writechar('s',10);
			for(i=1;i<=m;i++)writenum(Abs(ans[psx[i]]-ans[psy[i]]),i==m?10:32);
		}else writechar('N','o'),pc(10);
	}
	return output;
}
/*
1 2 1
1 3 2
1 4 3
1 5 4
2 6 4
3 6 3
3 7 4
4 8 4
5 8 3
7 8 1
*/
/*
2
8 10
1 2
1 3
1 4
1 5
2 6
3 6
3 7
4 8
5 8
7 8
2
4 3 4 5 6
4 4 5 6 7
5 4
1 2
1 3
2 4
2 5
2
2 3 4
2 2 5
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 57160kb

input:

2
8 10
1 2
1 3
1 4
1 5
2 6
3 6
3 7
4 8
5 8
7 8
2
4 3 4 5 6
4 4 5 6 7
5 4
1 2
1 3
2 4
2 5
2
2 3 4
2 2 5

output:

Yes
1 2 3 4 4 3 4 4 3 1
No

result:

ok 2 cases (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 7ms
memory: 56908kb

input:

129
2 1
1 2
1
1 1
2 1
1 2
2
1 1
1 2
3 2
1 2
1 3
1
1 1
3 2
1 2
1 3
1
1 2
3 2
1 2
1 3
1
1 3
3 2
1 2
1 3
1
2 1 2
3 2
1 2
1 3
1
2 1 3
3 2
1 2
1 3
1
2 2 3
3 2
1 2
1 3
1
3 1 2 3
3 2
1 2
1 3
2
1 1
1 2
3 2
1 2
1 3
2
1 1
1 3
3 2
1 2
1 3
2
1 1
2 1 2
3 2
1 2
1 3
2
1 1
2 1 3
3 2
1 2
1 3
2
1 1
2 2 3
3 2
1 2
1 3
...

output:

Yes
1
Yes
1
Yes
2 1
Yes
2 1
Yes
1 2
No
No
Yes
1 2
No
Yes
2 1
Yes
1 2
No
No
Yes
1 2
No
No
No
No
Yes
2 1
No
No
No
Yes
1 2
No
No
No
No
No
No
No
No
Yes
2 1
No
Yes
2 1
No
No
Yes
1 2
Yes
1 2
No
No
No
No
No
No
Yes
1 2
No
No
Yes
1 2
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
Yes
1 2
No
No
Yes
...

result:

wrong answer During Dijkstra for the given weights, some boundaries are not visited. (test case 32)