QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#31505#1774. Customs ControlsVingying0#WA 2ms32260kbC++231.7kb2022-05-08 16:23:362022-05-08 16:24:17

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 16:24:17]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:32260kb
  • [2022-05-08 16:23:36]
  • 提交

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;
        int ds=pq.top().first;
        pq.pop();
        if(ds!=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];
bool vis[MAXN];

int main()
{
    scanf("%d%d%d",&n,&m,&k);
    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);
    queue<int> q;
    q.push(n);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        for(auto v:g[u])if(a[u]+dis[v]==dis[u])
        {
            if(!vis[v])q.push(v);
            G[v].push_back(u);
            deg[u]++;
            vis[v]=1;
        }
    }
    for(auto v:G[1])if(v==n)
    {
        puts("impossible");
        return 0;
    }
    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]--;
            if(!deg[v])q.push(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("");
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 32260kb

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:

impossible

result:

wrong answer Output was 'impossible', but judge found a solution