QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#17007#1774. Customs ControlsJohnAlfnov#WA 3ms10860kbC++111.8kb2021-12-31 13:43:532022-05-04 12:45:28

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-04 12:45:28]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:10860kb
  • [2021-12-31 13:43:53]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
struct dij{
	int zz,wz;
	dij(int zz=0,int wz=0):zz(zz),wz(wz){}
	bool operator<(const dij &other)const{
		return wz>other.wz;
	}
};
vector<int>g[100005],g2[100005];
int deg[100005];
int a[100005],d1[100005],d2[100005];
int vist[100005];
int q[100005],ans[100005];
int main(){
	int n,m,k;
	cin>>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);
		g2[u].emplace_back(v);
		g2[v].emplace_back(u);
	}
	if(n==2&&k==1){
		printf("impossible\n");
		return 0;
	}
	priority_queue<dij>pq;
	memset(d1,63,sizeof(d1));
	memset(vist,0,sizeof(vist));
	d1[1]=a[1],pq.emplace(dij(1,d1[1]));
	while(pq.size()){
		int x=pq.top().zz;
		pq.pop();
		if(vist[x])continue;
		vist[x]=1;
		for(auto cu:g2[x]){
			if(d1[cu]>d1[x]+a[cu]){
				d1[cu]=d1[x]+a[cu];
				pq.emplace(dij(cu,d1[cu]));
			}
		}
	}
	memset(d2,63,sizeof(d2));
	memset(vist,0,sizeof(vist));
	d2[n]=a[n],pq.emplace(dij(n,d1[n]));
	while(pq.size()){
		int x=pq.top().zz;
		pq.pop();
		if(vist[x])continue;
		vist[x]=1;
		for(auto cu:g2[x]){
			if(d2[cu]>d2[x]+a[cu]){
				d2[cu]=d2[x]+a[cu];
				pq.emplace(dij(cu,d2[cu]));
			}
		}
	}
	for(int i=1;i<=n;++i)for(auto j:g2[i]){
		if(d1[i]+d2[j]==d1[n]){
			g[i].emplace_back(j);
			++deg[j];
		}
	}
	int head=0,tail=-1;
	for(int i=1;i<=n;++i)if(!deg[i])q[++tail]=i;
	while(head<=tail){
		int x=q[head++];
		for(auto cu:g[x]){
			--deg[cu];
			if(!deg[cu])q[++tail]=cu;
		}
	}
	for(int i=0;i<k;++i)ans[q[i]]=1;
	if(tail<k-1){
		for(int i=1;i<=n&&tail<k-1;++i){
			if(!ans[i]){
				ans[i]=1;
				++tail;
			}
		}
	}
	for(int i=1;i<=n;++i){
		if(ans[i])putchar('N');
		else putchar('S');
	}
	putchar('\n');
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 10860kb

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