QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#31502 | #1774. Customs Controls | Vingying0# | WA | 4ms | 29120kb | C++23 | 1.5kb | 2022-05-08 16:10:26 | 2022-05-08 16:10:29 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int MAXN=5e5+10;
int dis[MAXN],a[MAXN];
vector<int> g[MAXN],G[MAXN];
void dijkstra(int s)
{
priority_queue<pii,vector<pii>,greater<pii>> pq;
pq.push({0,s});
memset(dis,0x3f,sizeof(dis));
dis[s]=0;
while(!pq.empty())
{
int u=pq.top().second;pq.pop();
if(pq.top().first!=dis[u])continue;;
for(auto v:g[u])
{
if(a[v]+dis[u]<dis[v])
{
dis[v]=a[v]+dis[u];
pq.push({dis[v],v});
}
}
}
}
int n,m,k;
int op[MAXN],deg[MAXN];
int main()
{
scanf("%d%d%d",&n,&m,&k);
if(n==2&&m==1&&k==1)
{
puts("impossible");
return 0;
}
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=1;i<=m;i++)
{
int u,v;
scanf("%d%d",&u,&v);
g[u].push_back(v);
g[v].push_back(u);
}
dijkstra(1);
for(int i=1;i<=n;i++)
for(auto v:g[i])if(dis[v]==dis[i]+a[v])
{
G[i].push_back(v);
deg[v]++;
}
queue<int> q;
q.push(1);
while(!q.empty())
{
int u=q.front();q.pop();
if(k)op[u]=1,k--;
for(auto v:G[u])
{
deg[v]--;
}
}
for(int i=1;i<=n;i++)if(k&&!op[i])op[i]=1,k--;
for(int i=1;i<=n;i++)
{
if(op[i])putchar('N');
else putchar('S');
}
puts("");
}
详细
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 29120kb
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:
NNSSS
result:
wrong answer an alternating shortest path existed