QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#202154 | #1774. Customs Controls | yjf1225 | WA | 2ms | 7740kb | C++14 | 2.4kb | 2023-10-05 20:19:15 | 2023-10-05 20:19:15 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#define PII pair<int,int>
typedef long long LL;
using namespace std;
namespace yjf{
const int N=100010;
const int M=200010;
map<PII,bool> mp;
int h[N],ne[2*M],e[2*M],idx;
int Ans[N];
int w[N];
int tmp_1[M],idx_1;
int tmp_n[M],idx_n;
struct node{
int x;
LL d;
};
bool operator<(node a,node b){
return a.d>b.d;
}
priority_queue<node> q;
bool fl[N];
LL d[2][N];
void add(int x,int y){
e[++idx]=y;
ne[idx]=h[x];
h[x]=idx;
}
void dij(int st,int op){
memset(d[op],0x3f,sizeof(d[op]));
memset(fl,0,sizeof(fl));
q.push({st,w[st]});
d[op][st]=w[st];
while(q.size()){
node t=q.top();
q.pop();
if(fl[t.x]) continue;
fl[t.x]=true;
for(int i=h[t.x];i!=-1;i=ne[i]){
if(d[op][e[i]]>d[op][t.x]+w[e[i]]){
d[op][e[i]]=d[op][t.x]+w[e[i]];
q.push({e[i],d[op][e[i]]});
}
}
}
}
int main(){
memset(h,-1,sizeof(h));
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
//int op=0;
/*
if(k<n-k){
k=n-k;
op=1;
}
*/
//cout<<"!!!"<<op<<endl;
for(int i=1;i<=n;i++){
scanf("%d",&w[i]);
}
int x,y;
for(int i=1;i<=m;i++){
scanf("%d%d",&x,&y);
if(!mp[{x,y}]){
add(x,y);
add(y,x);
mp[{x,y}]=true;
mp[{y,x}]=true;
}
if(x==n){
tmp_n[++idx_n]=y;
}
if(x==1){
tmp_1[++idx_1]=y;
}
if(y==n){
tmp_n[++idx_n]=x;
}
if(y==1){
tmp_1[++idx_1]=x;
}
}
dij(1,0);
dij(n,1);
LL minn=d[0][n];
//1
if(mp[{1,n}] && n==2 && k==1){
printf("impossible\n");
return 0;
}
if(k>=2){
Ans[1]=1;
k--;
for(int i=1;i<=idx_1;i++){
if(d[1][tmp_1[i]]+w[1]==minn){
Ans[tmp_1[i]]=1;
k--;
if(k==0) break;
}
}
//cout<<k<<endl;
}
else if(k>=1){
Ans[1]=1;
k--;
}
for(int i=1;i<=n;i++){
if(Ans[i]==0 && k==0){
printf("P");
}
else{
if(Ans[i]==0){
k--;
}
printf("U");
}
}
return 0;
}
}
int main(){
//freopen("data15.in","r",stdin);
//freopen("data.out","w",stdout);
return yjf::main();
}
//8MB
/*
6 8 3
1 1 1 1 1 1
1 2
1 3
1 4
1 5
2 6
3 6
4 6
5 6
*/
详细
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 7740kb
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:
UPPPU
result:
wrong answer invalid character