QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#784347 | #1774. Customs Controls | ydzr00000 | WA | 2ms | 8708kb | C++17 | 2.6kb | 2024-11-26 14:43:09 | 2024-11-26 14:43:47 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
vector<int>e[100001],g[100001];
int a[100001];
struct vertex{
int id;
long long dis;
friend inline bool operator<(const vertex &a,const vertex &b)
{
return a.dis>b.dis;
}
};
priority_queue<vertex>Q;
vector<long long>dis[2];
bool vis[100001];
inline void Dijkstra(int s,vector<long long>&dis)
{
memset(vis,0,sizeof(vis));
fill(dis.begin(),dis.end(),1e12);
dis[s]=0;
Q.push({s,0});
while(!Q.empty())
{
auto [u,d]=Q.top();
Q.pop();
if(vis[u])
continue;
vis[u]=true;
for(auto to: e[u])
{
long long nw=d+a[to];
if(nw>dis[to])
{
dis[to]=nw;
Q.push({to,nw});
}
}
}
}
vector<pair<int,int>>Eset;
char ch[300001];
int in[300001];
int main(){
int n,m,k;
scanf("%d %d %d",&n,&m,&k);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
bool flg=false;
for(int i=1;i<=m;i++)
{
int u,v;
scanf("%d %d",&u,&v);
e[u].push_back(v);
e[v].push_back(u);
flg|=(u==1&&v==n);
flg|=(u==n&&v==1);
Eset.push_back({u,v});
}
dis[0].resize(n+1);
dis[1].resize(n+1);
Dijkstra(1,dis[0]);
Dijkstra(n,dis[1]);
for(auto [u,v]: Eset)
{
if(dis[0][u]+dis[1][v]==dis[0][n])
g[u].push_back(v),in[v]++;
if(dis[0][v]+dis[1][u]==dis[0][n])
g[v].push_back(u),in[u]++;
}
fill(ch+1,ch+n+1,'P');
if(flg)
{
if(n==2&&k==1)
{
puts("impossible");
return 0;
}
if(k>1)
{
ch[1]=ch[n]='U';
k-=2;
int now=2;
while(k)
{
ch[now]='U';
now++;
k--;
}
}
else if(k==1)
ch[2]='U';
}
else
{
queue<int>Q;
vector<int>ord;
for(int i=1;i<=n;i++)
if(!in[i])
Q.push(i);
while(!Q.empty())
{
int u=Q.front();
Q.pop();
ord.push_back(u);
for(auto to: g[u])
{
in[to]--;
if(!in[to])
Q.push(to);
}
}
for(int i=0;i<k;i++)
ch[ord[i]]='U';
}
string ans="";
for(int i=1;i<=n;i++)
ans+=ch[i];
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 8708kb
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