QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#817#309790#8128. Alternating Pathsnodgducup-team266Failed.2024-09-11 20:08:222024-09-11 20:08:23

Details

In file included from /usr/include/c++/13/string:43,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from answer.code:24:
/usr/include/c++/13/bits/allocator.h: In destructor ‘constexpr std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int> > >::_Vector_impl::~_Vector_impl()’:
/usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to ‘always_inline’ ‘constexpr std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = std::pair<int, int>]’: target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53:
/usr/include/c++/13/bits/stl_vector.h:133:14: note: called from here
  133 |       struct _Vector_impl
      |              ^~~~~~~~~~~~

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#309790#8128. Alternating Pathsucup-team266#AC ✓683ms3920kbC++203.0kb2024-01-20 20:46:462024-01-20 20:46:46

answer

/*
Things to notice:
1. do not calculate useless values
2. do not use similar names
 
Things to check:
1. submit the correct file
2. time (it is log^2 or log)
3. memory
4. prove your naive thoughts 
5. long long
6. corner case like n=0,1,inf or n=m
7. check if there is a mistake in the ds or other tools you use
8. fileio in some oi-contest

9. module on time 
10. the number of a same divisor in a math problem
11. multi-information and queries for dp and ds problems
*/

#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
const int mod=998244353;
const int inf=0x3f3f3f3f;
int n,m,U[305],V[305],col[305],perm[305];
int fa[105];
int find(int x)
{
	if(fa[x]==x) return x;
	return fa[x]=find(fa[x]);
}
void merge(int x,int y)
{
	int xx=find(x),yy=find(y);
	if(xx!=yy) fa[xx]=yy;
}
mt19937 rnd(114514);

int vis[105][2];
vector <pii > g[105];
bool chk()
{
	for(int i=1;i<=n;i++) g[i].clear();
	for(int i=1;i<=m;i++) g[U[i]].pb(mp(V[i],col[i])),g[V[i]].pb(mp(U[i],col[i]));
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++) vis[j][0]=vis[j][1]=0;
		vis[i][0]=vis[i][1]=1;
		queue <pii > q;
		q.push(mp(i,0)),q.push(mp(i,1));
		while(q.size())
		{
			int u=q.front().fi,c=q.front().se;
			q.pop();
			for(int j=0;j<g[u].size();j++) if(g[u][j].se!=c)
			{
				int v=g[u][j].fi;
				if(vis[v][c^1]) continue;
				vis[v][c^1]=1,q.push(mp(v,(c^1)));
			}
		}
		for(int j=1;j<=n;j++) if(!vis[j][0]&&!vis[j][1]) return 0;
	}
	return 1;
}
int tr[305],dep[305],vis_dfs[105];
void dfs0(int u,int par)
{
	vis_dfs[u]=1;
	for(int i=0;i<g[u].size();i++)
	{
		int v=g[u][i].fi;
		if(v==par||vis_dfs[v]) continue;
		dep[v]=dep[u]+1,tr[g[u][i].se]=1,dfs0(v,u);
	}
}
bool work()
{
	for(int i=1;i<=n;i++) fa[i]=i,g[i].clear(),dep[i]=vis_dfs[i]=0;
	for(int i=1;i<=m;i++) perm[i]=i,tr[i]=0,g[U[i]].pb(mp(V[i],i)),g[V[i]].pb(mp(U[i],i));
	for(int i=1;i<=n;i++) for(int j=g[i].size()-1;j>=0;j--) swap(g[i][j],g[i][rnd()%(j+1)]);
	
//	for(int i=m;i>=1;i--) swap(perm[i],perm[1+rnd()%i]);
//	for(int i=1;i<=m;i++) 
//	{
//		int x=perm[i];
//		if(find(U[x])!=find(V[x])) merge(U[x],V[x]),tr[x]=1,g[U[x]].pb(mp(V[x],x)),g[V[x]].pb(mp(U[x],x));
//	}
	dfs0(1+rnd()%n,-1);
	for(int i=1;i<=m;i++)
	{
		if(tr[i]) col[i]=min(dep[U[i]],dep[V[i]])%2;
		else
		{
			col[i]=rnd()%2;
//			int x=U[i],y=V[i];
//			if(rnd()%2) swap(x,y);
//			col[i]=(dep[x]%2);
		}
	}
//	for(int i=1;i<=m;i++) cout<<col[i];
//	cout<<"\n";
//	system("pause");
	if(chk())
	{
		for(int i=1;i<=m;i++) cout<<(col[i]?"R":"B");
		cout<<"\n";
		return 1;
	}
	return 0;
}
void solve()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++) cin>>U[i]>>V[i];
	for(int _=0;_<1500;_++) if(work()) return;
	cout<<"IMPOSSIBLE\n";
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int _=1;
	cin>>_;
	while(_--) solve();
	return 0;
}