QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#201839 | #1774. Customs Controls | wert | WA | 2ms | 14028kb | C++14 | 2.5kb | 2023-10-05 16:59:11 | 2023-10-05 16:59:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace ac{
const int MAXN = 1000005, inf = 0x7fffffff / 2;
int n, m, k, t[MAXN], u, v, d1[MAXN], top1, d2[MAXN], top2;
int head[MAXN], cnt;
char ch[MAXN];
struct node{
int next, to;
}ed[4 * MAXN];
void add_edge(int u, int v){
ed[++cnt].next = head[u];
ed[cnt].to = v;
head[u] = cnt;
}
int did[MAXN], vis[MAXN];
struct line{
int dot, dis;
};
bool operator < (line a, line b){
return a.dis > b.dis;
}
priority_queue<line> q;
void dijkstra(int s){
for(int i = 1;i <= n;i++){
did[i] = inf;
vis[i] = 0;
}did[s] = t[s];
q.push((line){s, did[s]});
while(q.size()){
int tmpdot = q.top().dot;
q.pop();
if(vis[tmpdot]) continue;
vis[tmpdot] = 1;
for(int i = head[tmpdot];i;i = ed[i].next){
int v = ed[i].to;
if(did[tmpdot] + t[v] == did[v]){
if(tmpdot == 1) d1[++top1] = v;
if(v == n) d2[++top2] = tmpdot;
}
else if(did[tmpdot] + t[v] < did[v]){
did[v] = did[tmpdot] + t[v];
q.push((line){v, did[v]});
if(tmpdot == 1) d1[++top1] = v;
if(v == n){
top2 = 0;
d2[++top2] = tmpdot;
}
}
}
}
}
int main(){
scanf("%d%d%d", &n, &m, &k);
for(int i = 1;i <= n;i++) scanf("%d", &t[i]);
for(int i = 1;i <= m;i++){
scanf("%d%d", &u, &v);
add_edge(u, v);
add_edge(v, u);
}
dijkstra(1);
for(int i = 0;i < n;i++) ch[i] = '.';
int n1 = k, n2 = n - k;
if(max(n1, n2) < min(top1, top2) + 1){
printf("impossible");
return 0;
}
if(top1 <= top2){
if(n1 > n2){
for(int i = 1;i <= top1;i++){
ch[d1[i] - 1] = 'U';
n1--;
}ch[0] = 'U';
n1--;
}else{
for(int i = 1;i <= top1;i++){
ch[d1[i] - 1] = 'P';
n2--;
}ch[0] = 'P';
n2--;
}
}else{
if(n1 > n2){
for(int i = 1;i <= top2;i++){
ch[d2[i] - 1] = 'U';
n1--;
}ch[n - 1] = 'U';
n1--;
}else{
for(int i = 1;i <= top2;i++){
ch[d2[i] - 1] = 'P';
n2--;
}ch[n - 1] = 'P';
n2--;
}
}//cout << ch << '\n';
for(int i = 0;i < n;i++){
if(ch[i] == '.'){
if(n1){
ch[i] = 'U';
n1--;
}else{
ch[i] = 'P';
n2--;
}
}putchar(ch[i]);
}//printf("%d %d", n1, n2);
// while(1);
return 0;
}
} int main(){
// freopen("data.in", "r", stdin);
//// freopen("ex_data2.in", "r", stdin);
// freopen("data.out", "w", stdout);
return ac::main();
}//6MB
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 14028kb
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:
PUUPP
result:
wrong answer invalid character