QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#202101 | #1774. Customs Controls | lidong | WA | 1ms | 9824kb | C++14 | 2.4kb | 2023-10-05 19:22:06 | 2023-10-05 19:22:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace ld{
struct edge{
int next;
int to;
int w;
}ed[400050], ed2[400050];int ed_cnt;int ed_cnt2;
int h[100050];int h2[100050];
void add_edge(int x,int y,int w){
ed[++ed_cnt]={h[x],y,w};
h[x]=ed_cnt;
}
void add_edge2(int x,int y,int w){
ed2[++ed_cnt2]={h2[x],y,w};
h2[x]=ed_cnt2;
}
int n,m,k;
int val[100050];
struct node{
int pos;
int dis;
bool operator < (const node & b)const {
return dis>b.dis;
}
};
int d[2][100005];
int vis[2][100005];
priority_queue<node> q;
void dij(int s){
int st;
if(s==1)st=0;
if(s==n)st=1;
for(int i=1;i<=n;i++)
d[st][i]=1e9;
d[st][s]=0;
q.push({s,0});
while(!q.empty()){
int u=q.top().pos;
q.pop();
if(vis[st][u])continue;
vis[st][u]=1;
if(st==0){
for(int i=h[u];i;i=ed[i].next){
int v=ed[i].to;
int w=ed[i].w;
if(d[st][v]>d[st][u]+w){
d[st][v]=d[st][u]+w;
q.push({v,d[st][v]});
}
}
}
else {
for(int i=h2[u];i;i=ed2[i].next){
int v=ed2[i].to;
int w=ed2[i].w;
if(d[st][v]>d[st][u]+w){
d[st][v]=d[st][u]+w;
q.push({v,d[st][v]});
}
}
}
}
}
int Cnt;
int col[100050];
int onpath[100050];
int vst[100050];
void Print(){
for(int i=1;i<=n;i++){
if(col[i])cout<<'N';
else cout<<'S';
}
cout<<'\n';
}
queue<int> chg;
int main(){
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=n;i++)scanf("%d",val+i);
for(int i=1;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
add_edge(x,y,val[x]);
add_edge(y,x,val[y]);
add_edge2(y,x,val[x]);
add_edge2(x,y,val[y]);
}
int Cnt=0;
int noton=0;
dij(1);
dij(n);
for(int i=1;i<=n;i++){
if(d[0][i]+d[1][i]==d[0][n]){
onpath[i]=1;
col[i]=1;Cnt++;
}
else noton++;
}
if(Cnt<=k){
int need=k-Cnt;
for(int i=1;i<=n;i++)
if(need&&(!col[i])){
col[i]=1;
need--;
}
Print();
return 0;
}
chg.push(n);vst[n]=1;
while(chg.size()){
int now=chg.front();chg.pop();
col[now]=0;Cnt--;
if(Cnt==k)
break;
for(int i=h[now];i;i=ed[i].next){
int v=ed[i].to;
if(vst[v])continue;
if(onpath[v]){
chg.push({v});
vst[v]=1;
}
}
}
Print();
return 0;
}
}
int main(){
ld::main();
return 0;
}
//13mb
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 9824kb
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: 1ms
memory: 9804kb
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: 1ms
memory: 7688kb
input:
2 1 2 6124 7094 2 1
output:
NN
result:
ok accepted
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 7780kb
input:
2 1 1 6901 1417 2 1
output:
NS
result:
wrong answer an alternating shortest path existed