QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#407#205513#21694. 【NOIP Round #3】抓内鬼ytb2024ytb2024Failed.2023-10-07 16:22:402023-10-07 16:22:40

Details

Extra Test:

Accepted
time: 91ms
memory: 719384kb

input:

3 2 0
1 1 1
1 2
2 3

output:

PPP

result:

ok ok

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#205513#21694. 【NOIP Round #3】抓内鬼ytb2024100 ✓156ms735180kbC++232.4kb2023-10-07 16:21:492023-10-07 16:21:49

answer

#include<bits/stdc++.h>
#define int long long
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,l,r) for(int i=r;i>=l;i--)
using namespace std;
const int N=1e7+5,M=2e5+5;
vector<int>e[N];
vector<int>prt[N],ddd[N]; 
int n,m,k,t[N],bg[M],ed[M],que[N],dis[N],l=1,r,qp[N],ggm,vis[N];
inline bool dfs(int x)
{
	if(x==1)return 0;
	bool ans=0;
	for(auto y:prt[x])
	{
		if(bool(ggm&qp[x-1])==bool(ggm&qp[y-1]))return 1;
		if(dfs(y))return 1;
	}
	return 0;
}
inline void dfsdfs(int x)
{
	if(vis[x])return;
	vis[x]=1;
	for(auto y:prt[x])
	{
		if(y==1)ddd[1].push_back(x);
		else dfsdfs(y);
	}
}
signed main()
{
//	freopen("data.in","r",stdin);
//	freopen("data.out","w",stdout);
	ios::sync_with_stdio(false);cin.tie(0);
	cin>>n>>m>>k;
	qp[0]=1;
	rep(i,1,n)qp[i]=qp[i-1]*2;
	rep(i,1,n)cin>>t[i];
	rep(i,1,m)cin>>bg[i]>>ed[i],e[bg[i]].push_back(ed[i]),e[ed[i]].push_back(bg[i]);
	rep(i,1,n)dis[i]=9e18;
	que[++r]=1,dis[1]=t[1];
	while(l<=r)
	{
		int to=que[l++];
		for(auto y:e[to])
		{
			if(dis[to]+t[y]<dis[y])
			{
				prt[y].clear();
				prt[y].push_back(to);
				dis[y]=dis[to]+t[y];
				que[++r]=y;
			}
			else if(dis[to]+t[y]==dis[y])prt[y].push_back(to);
		}
	}
	if(n==2&&k==1)
	{
		cout<<"impossible";
		return 0;
	}
//	if(k==1)
//	{
//		bool ans=0;
//		rep(i,1,n)
//		{
//			ggm=qp[i-1];
//			if(dfs(n))
//			{
//				rep(j,1,n)cout<<((i&qp[j-1])?"U":"P");
//				ans=1;
//				break;
//			}			
//		}
//		if(!ans)cout<<"impossible";
//		return 0;
//	}
//	if(n<=15)
//	{
//		bool ans=0;
//		rep(i,0,qp[n]-1)
//		{
//			int ggb=i,num=0;
//			rep(j,1,n)if(i&qp[j-1])num++;
//			if(num!=k)continue;
//			ggm=i;
////			rep(j,1,n)cout<<bool(i&qp[j-1])<<" ";
////			cout<<'\n';
//			if(dfs(n))
//			{
//				rep(j,1,n)cout<<((i&qp[j-1])?"U":"P");
//				ans=1;
//				break;
//			}
//		}
//		if(!ans)cout<<"impossible";
//		return 0;
//	}
	dfsdfs(n);
//	if(ddd[1].size()+1<=max(n-k,k))
	{
		string s;
		if(k>n-k)
		{
			rep(i,1,n)s+='P';
			int sum=1;
			if(k)s[0]='U';
			for(auto y:ddd[1])if(sum<k)
			{
				sum++;		
				s[y-1]='U';
			}
			rep(i,1,n)if(s[i-1]=='P'&&sum<k)sum++,s[i-1]='U';
		}
		else
		{
			rep(i,1,n)s+='U';
			int sum=1;
			if(n-k!=0)s[0]='P';
			for(auto y:ddd[1])if(sum<n-k)
			{
				sum++;		
				s[y-1]='P';
			}
			rep(i,1,n)if(s[i-1]=='U'&&sum<n-k)sum++,s[i-1]='P';
		}
		cout<<s;
	}
//	else cout<<"impossible";
	return 0;
}
/*
3 2 2
1 9 4
2 3
1 2
*/