QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#201960 | #1774. Customs Controls | mifik | WA | 1ms | 5592kb | C++14 | 1.7kb | 2023-10-05 17:56:55 | 2023-10-05 17:56:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace hw {
int n,m,k,kk,cnt,t[100005],head[100005],tot,d[100005];
int ans[100005];
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >q;
struct node {
int to,next;
}edge[400005];
void add(int u,int v) {
tot++;
edge[tot].to=v;
edge[tot].next=head[u];
head[u]=tot;
}
void Dij() {
d[1]=t[1];
q.push(make_pair(d[1],1));
int u,v;
while (!q.empty()) {
u=q.top().second;
q.pop();
for (int i=head[u];i;i=edge[i].next) {
v=edge[i].to;
if (d[u]+t[v]<d[v]) {
d[v]=d[u]+t[v];
q.push(make_pair(d[v],v));
}
}
}
}
void enume(int u) {
int v;
for (int i=head[u];i;i=edge[i].next) {
v=edge[i].to;
if (d[v]+t[u]==d[u]) {
if (cnt==0) {
cnt=-1;
break;
}
ans[v]=1;
cnt--;
}
}
}
void out() {
if (cnt==-1) {
printf("impossible");
return ;
}
char a,b;
if (kk==k) a='S',b='N';
else a='N',b='S';
for (int i=1;i<=n;i++) {
if (ans[i]==0) {
if (cnt) {
cnt--;
printf("%c",a);
} else printf("%c",b);
} else {
printf("%c",a);
}
}
}
int main() {
// freopen("ex_data6.in","r",stdin);
scanf("%d%d%d",&n,&m,&k);
cnt=kk=max(k,n-k);
for (int i=1;i<=n;i++) {
scanf("%d",&t[i]);
d[i]=1e9;
}
int u,v;
for (int i=1;i<=m;i++) {
scanf("%d%d",&u,&v);
if ((u==1 && v==n) || (u==n && v==1)) {
ans[1]=ans[n]=1,cnt-=2;
out();
return 0;
}
add(u,v);
add(v,u);
}
Dij();
ans[n]=1,cnt--;
enume(n);
out();
return 0;
}
}
int main() {
//10M
hw::main();
return 0;
}
/*
2 1 2
6124 7094
2 1
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5592kb
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:
NNSSN
result:
wrong answer number of N:s not equal to k