QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#17101 | #1774. Customs Controls | _silhouette_# | WA | 5ms | 12084kb | C++14 | 2.2kb | 2022-01-03 16:44:23 | 2022-05-04 13:19:24 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int Max_N=1e5,Max_M=2e5,Inf=(1e9)+1;
int n,m,K,Num,lin[Max_N+5],t[Max_N+5],dis[Max_N+5],Dis[Max_N+5],vis[Max_N+5],In[Max_N+5];
char ans[Max_N+5];
priority_queue< pair<int,int> > Q;
queue<int> q;
vector<int> a[Max_N+5];
struct Edge{
int Id,Next;
} e[Max_M*2+5];
struct EDGE{
int u,v;
} E[Max_M+5];
void Insert(int x,int y){
e[++Num].Next=lin[x]; lin[x]=Num; e[Num].Id=y;
}
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",&E[i].u,&E[i].v);
Insert(E[i].u,E[i].v);
Insert(E[i].v,E[i].u);
}
for(int i=1;i<=n;i++) dis[i]=Inf;
dis[1]=t[1]; Q.push(make_pair(-dis[1],1));
for(;Q.size();){
int x=Q.top().second; Q.pop();
if(vis[x]) continue; vis[x]=1;
for(int i=lin[x];i;i=e[i].Next)
if(dis[x]+t[e[i].Id]<dis[e[i].Id]){
dis[e[i].Id]=dis[x]+t[e[i].Id];
Q.push(make_pair(-dis[e[i].Id],e[i].Id));
}
}
if(dis[n]==2){
if(K>=2){
putchar('N'); K-=2;
for(int i=2;i<n;i++)
if(K) putchar('N'),--K;
else putchar('S');
putchar('N'); puts("");
} else if(n-K>=2){
putchar('S');
for(int i=2;i<=n;i++)
if(K) putchar('N'),--K;
else putchar('S');
puts("");
} else puts("impossible");
return 0;
}
for(int i=1;i<=n;i++) Dis[i]=Inf,vis[i]=0;
Dis[n]=t[n]; Q.push(make_pair(-Dis[n],n));
for(;Q.size();){
int x=Q.top().second; Q.pop();
if(vis[x]) continue; vis[x]=1;
for(int i=lin[x];i;i=e[i].Next)
if(Dis[x]+t[e[i].Id]<Dis[e[i].Id]){
Dis[e[i].Id]=Dis[x]+t[e[i].Id];
Q.push(make_pair(-Dis[e[i].Id],e[i].Id));
}
}
for(int i=1;i<=m;i++){
if(dis[E[i].u]+Dis[E[i].v]==dis[n])
a[E[i].u].push_back(E[i].v),++In[E[i].v];
if(dis[E[i].v]+Dis[E[i].u]==dis[n])
a[E[i].v].push_back(E[i].u),++In[E[i].u];
}
q.push(1);
for(int i=1;i<=n;i++) vis[i]=0;
for(;q.size();){
int x=q.front(); q.pop(); vis[x]=1;
if(K) ans[x]='N',--K;
else ans[x]='S';
for(int i=0;i<a[x].size();i++){
--In[a[x][i]];
if(In[a[x][i]]==0) q.push(a[x][i]);
}
}
for(int i=1;i<=n;i++)
if(!vis[i]){
if(K) ans[i]='N',--K;
else ans[i]='S';
}
for(int i=1;i<=n;i++) printf("%c",ans[i]);
puts("");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 11868kb
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:
NSSSN
result:
ok accepted
Test #2:
score: 0
Accepted
time: 5ms
memory: 11964kb
input:
10 9 5 1 1 1 1 1 1 1 1 1 1 9 5 7 1 8 1 10 1 5 3 6 1 2 1 3 2 4 1
output:
NNNNSSSSSN
result:
ok accepted
Test #3:
score: 0
Accepted
time: 4ms
memory: 12084kb
input:
2 1 2 6124 7094 2 1
output:
NN
result:
ok accepted
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 11932kb
input:
2 1 1 6901 1417 2 1
output:
NS
result:
wrong answer an alternating shortest path existed