QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#201796 | #1774. Customs Controls | mifik | WA | 1ms | 5964kb | C++14 | 1.6kb | 2023-10-05 16:47:57 | 2023-10-05 16:47:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace hw {
int n,m,k,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 ;
}
for (int i=1;i<=n;i++) {
if (ans[i]==0) {
if (cnt) {
cnt--;
printf("S");
} else printf("N");
} else {
printf("S");
}
}
}
int main() {
// freopen("ex_data6.in","r",stdin);
scanf("%d%d%d",&n,&m,&k);
cnt=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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3884kb
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:
SSNNS
result:
ok accepted
Test #2:
score: 0
Accepted
time: 1ms
memory: 5964kb
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:
SSSSNNNNNS
result:
ok accepted
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3868kb
input:
2 1 2 6124 7094 2 1
output:
SS
result:
wrong answer number of N:s not equal to k