QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#201999#1774. Customs Controlsdog_of_zimuWA 1ms7456kbC++142.1kb2023-10-05 18:16:132023-10-05 18:16:13

Judging History

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

  • [2023-10-05 18:16:13]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7456kb
  • [2023-10-05 18:16:13]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<queue>
#define int long long
using namespace std;
namespace LZZMD{
	const int N = 1e5, M = 2e5, inf = 0x7fffffffffffffff / 2;
	struct edge{
		int nxt, to;
	} e[M * 6 + 10];
	int head[N * 3 + 10], cnt;
	int time[N + 10];
	int n, m, k;
	inline void add(int u, int v){
		e[++cnt] = {head[u], v};
		head[u] = cnt;
	}
	struct node{
		int u, dis;
	};
	priority_queue<node> q;
	bool operator < (node x, node y){
		return x.dis > y.dis;
	}
	int dis[N + 10], vis[N + 10];
	inline void dijkstra(int s){
		for(int i = 1; i <= n; i++)
			dis[i] = inf;
		dis[s] = time[s];
		q.push({s, dis[s]});
		while(q.size()){
			int u = q.top().u;
			q.pop();
			if(vis[u])
				continue;
			vis[u] = 1;
			for(int i = head[u]; i; i = e[i].nxt){
				int v = e[i].to;
				if(dis[v] > dis[u] + time[v]){
					dis[v] = dis[u] + time[v];
					q.push({v, dis[v]});
				}
			}
		}
	}
	bool ans[N + 10];
	int main(){
		scanf("%lld%lld%lld", &n, &m, &k);
		for(int i = 1; i <= n; i++)
			scanf("%lld", &time[i]);
		for(int i = 1, u, v; i <= m; i++){
			scanf("%lld%lld", &u, &v);
			add(u, v), add(v, u);
		}
		dijkstra(1);
		int s1 = 1, s2 = 1;
		for(int i = head[1]; i; i = e[i].nxt)
			if(dis[1] + time[e[i].to] == dis[e[i].to])
				s1++;
		for(int i = head[n]; i; i = e[i].nxt)
			if(dis[e[i].to] + time[n] == dis[n])
				s2++;
		int tmp;
		if(s1 <= s2){
			tmp = s1;
			ans[1] = 1;
			for(int i = head[1]; i; i = e[i].nxt)
				if(dis[1] + time[e[i].to] == dis[e[i].to])
					ans[e[i].to] = 1;
		}
		else{
			tmp = s2;
			ans[n] = 1;
			for(int i = head[n]; i; i = e[i].nxt)
				if(dis[e[i].to] + time[n] == dis[n])
					ans[e[i].to] = 1;
		}
		if(tmp > k && tmp > n - k){
			puts("impossible");
			return 0;
		}
		int flag = 0;
		if(k < n - k)
			k = n - k, flag = 1;
		for(int i = 1; i <= n; i++){
			if(!ans[i] && tmp < k)
				ans[i] = 1;
			if(!flag)
				putchar(ans[i] ? 'U' : 'P');
			else
				putchar(ans[i] ? 'P' : 'U');
		}
		return 0;
	}
}
signed main(){
	return LZZMD::main();
}
//14MB

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7456kb

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:

PPPPP

result:

wrong answer invalid character