QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#389380#1774. Customs ControlsSroundWA 1ms10084kbC++141.9kb2024-04-14 10:44:572024-04-14 10:44:57

Judging History

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

  • [2024-04-14 10:44:57]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:10084kb
  • [2024-04-14 10:44:57]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

inline int read()
{
	int x=0;bool f=0;char ch=getchar();
	while(ch<'0' || ch>'9') {if(ch=='-') f=1;ch=getchar();}
	while(ch>='0' && ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return f?-x:x;
}

#define x first
#define y second
#define pb push_back
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)

typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ull;
const int N=1e5+10,M=4e5+10;

int n,m,K;
int h[N],e[M],ne[M],w[N],idx;
int dist[N],ans[N];
int q1[N],qn[N],tmp[N],both[N];
bool fr1[N],ton[N];
priority_queue<PII,vector<PII>,greater<PII> > heap;

void add(int a,int b) {e[idx]=b,ne[idx]=h[a],h[a]=idx++;}

void prework()
{
	memset(dist,0x3f,sizeof(dist));
	heap.push({0,1}),dist[1]=0;
	while(heap.size()) {
		PII t=heap.top(); heap.pop();
		if(t.x>dist[t.y]) continue;
		for(int i=h[t.y];i!=-1;i=ne[i]) {
			int j=e[i];
			if(dist[j]>t.x+w[j]) dist[j]=t.x+w[i],heap.push({dist[j],j});
		}
	}
}

int main()
{
	n=read(),m=read(),K=read(),memset(h,-1,sizeof(h));
	for(int i=1;i<=n;i++) w[i]=read();
	for(int i=1,u,v;i<=m;i++) u=read(),v=read(),add(u,v),add(v,u);
	prework();
	
	for(int i=0;i<idx;i+=2) {
		int a=e[i^1],b=e[i]; if(a>b) swap(a,b);
		if(a==1 && dist[b]==dist[a]+w[b]) fr1[b]=1;
		if(b==n && dist[n]==dist[a]+w[b]) ton[a]=1;
	}
	if(n==2 && fr1[n] && K==1) {puts("impossible"); return 0;}
	
	int cnt=1,sum=0;
	for(int i=1;i<=n;i++) if(ton[i]) ++cnt;
	sum=min(cnt,max(K,n-K))-1,ans[n]=1;
	// cout<<sum<<' '<<ans[1]<<' '<<ans[2]<<' '<<ans[n]<<' '<<ton[2]<<endl;
	for(int i=n-1;i>=1 && sum>0;i--) if(ton[i]) ans[i]=1,--sum;
	sum=max(K,n-K)-cnt;
	// cout<<sum<<' '<<ans[1]<<' '<<ans[2]<<' '<<ans[n]<<endl;
	for(int i=1;i<=n && sum>0;i++) if(!ans[i]) ans[i]=1,--sum;
	
	char cur='N',rev='S';
	if(K>=n-K) cur='S',rev='N';
	rep(i,1,n) printf("%c",ans[i]?rev:cur);
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 10084kb

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: 9924kb

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: 0ms
memory: 8124kb

input:

2 1 2
6124 7094
2 1

output:

NN

result:

ok accepted

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 8216kb

input:

2 1 1
6901 1417
2 1

output:

SN

result:

wrong answer an alternating shortest path existed