QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#784567#1774. Customs ControlsliuziqinWA 2ms8680kbC++141.4kb2024-11-26 15:21:552024-11-26 15:21:56

Judging History

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

  • [2024-11-26 15:21:56]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:8680kb
  • [2024-11-26 15:21:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=200005;
struct edge{
	int to,nxt;
}e[N<<1];
int head[N],cnt;
void add(int u,int v){
	e[++cnt].to=v;
	e[cnt].nxt=head[u];
	head[u]=cnt;
}
int w[N];
int n,m,k;
int u[N],v[N];
struct spt{
	int dis[N],used[N];
	void dij(int rt){
		memset(used,0,sizeof(used));
		memset(dis,0x3f,sizeof(dis));
		priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >q;
		dis[rt]=w[rt];
		while(!q.empty()){
			int u=q.top().second;
			q.pop();
			if(used[u])continue;
			used[u]=1;
			for(int i=head[u];i;i=e[i].nxt){
				int v=e[i].to;
				if(dis[v]>dis[u]+w[v]){
					dis[v]=dis[u]+w[v];
					q.push({dis[v],v});
				}
			}
		}
	}
}g1,g2;
char ans[N];
bool on[N];
int sum=0;
int main(){
//	freopen("catch.in","r",stdin);
//	freopen("catch.out","w",stdout);
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)cin>>w[i];
	for(int i=1;i<=m;i++){
		cin>>u[i]>>v[i];
		add(u[i],v[i]);
		add(v[i],u[i]);
	}
	g1.dij(1);
	g2.dij(n);
	for(int i=1;i<=n;i++){
		if(g1.dis[i]+g2.dis[i]-w[i]==g1.dis[n])on[i]=1;
	}
	for(int i=1;i<=n;i++)sum+=on[i];
	int tot=k;
	char now='U',rest='P';
	if(k<n-k)now='P',rest='U',tot=n-k;
	for(int i=1;i<=n;i++)ans[i]=rest;
	if(tot>=sum){
		for(int i=1;i<=n;i++)if(on[i])ans[i]=now,tot--;
		for(int i=1;i<=n&&tot;i++)if(ans[i]!=now){
			ans[i]=now;
			tot--;
		}
		for(int i=1;i<=n;i++)cout<<ans[i];
		return 0;
	}
	cout<<"impossible\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 8680kb

input:

5 10 2
1 1 1 1 1
3 4
5 4
3 1
4 1
3 5
2 1
2 4
2 5
1 5
2 3

output:

PPUUP

result:

wrong answer invalid character