QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#269030#1774. Customs ControlsTerkWA 15ms129448kbC++141.5kb2023-11-29 11:04:462023-11-29 11:04:46

Judging History

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

  • [2023-11-29 11:04:46]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:129448kb
  • [2023-11-29 11:04:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e6+10;
int n,m,k,f;
int Rem[N],ans[N];
int u[N],v[N];
int dis[2][N],vis[N];
int idx[N],tot;
vector<int> e[N],E[N];
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q; 
void dij(int s,int op){
	memset(dis[op],0x3f,sizeof(dis[op]));
	memset(vis,0,sizeof(vis));
	dis[op][s]=Rem[s];
	q.push({0,s});
	while(!q.empty()){
		int x=q.top().second;
		q.pop();
		if(vis[x]) continue;
		vis[x]=1;
		for(auto y:e[x]){
			if(dis[op][y]>Rem[y]+dis[op][x]){
				dis[op][y]=Rem[y]+dis[op][x];
				q.push({dis[op][y],y});
			}
		}
	}
}
void dfs(int x,int fa){
	++tot;
	idx[tot]=x;
	for(auto y:E[x]){
		if(y==fa) continue;
		dfs(y,x);
	}
}
int main(){
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++) cin>>Rem[i];
	for(int i=1;i<=m;i++){
		cin>>u[i]>>v[i];
		e[u[i]].push_back(v[i]);
		e[v[i]].push_back(u[i]);
		if(u[i]==1&&v[i]==n||u[i]==n&&v[i]==1) f=1;
	}
	dij(1,0);
	dij(n,1);
	for(int i=1;i<=m;i++){
		if(dis[0][u[i]]+dis[1][v[i]]==dis[0][n]){
			E[u[i]].push_back(v[i]);
			E[v[i]].push_back(u[i]);
		}
	}
	dfs(1,0);
	if(f){
		if(n==2&&k==1) cout<<"impossible";
		else if(k<2){
			for(int i=1;i<n-k;i++) cout<<'S';
			for(int i=n-k;i<n;i++) cout<<'N';
			cout<<'S';
		}
		else{
			for(int i=1;i<k;i++) cout<<'N';
			for(int i=k;i<n;i++) cout<<'S';
			cout<<'N';
		}
		return 0;
	}
	for(int i=1;i<=k;i++) ans[idx[i]]=1;
	for(int i=1;i<=n;i++) cout<<(ans[i]?'N':'S');
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 15ms
memory: 126812kb

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: 12ms
memory: 126784kb

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

input:

2 1 2
6124 7094
2 1

output:

NN

result:

ok accepted

Test #4:

score: 0
Accepted
time: 12ms
memory: 126932kb

input:

2 1 1
6901 1417
2 1

output:

impossible

result:

ok accepted

Test #5:

score: -100
Wrong Answer
time: 3ms
memory: 129448kb

input:

50 67 25
5 10 5 4 3 3 8 7 10 4 6 6 9 8 5 1 5 9 3 2 3 8 9 9 2 8 7 8 9 8 3 3 10 7 5 5 7 1 6 9 4 6 9 10 4 10 9 10 9 5
45 35
27 17
11 14
34 1
49 37
4 2
9 3
42 9
13 25
40 32
38 17
28 1
26 14
13 19
41 40
38 40
12 6
14 7
47 25
30 21
32 22
7 6
16 12
15 9
20 16
29 3
21 8
19 9
18 23
43 5
5 3
11 35
10 7
36 16
...

output:

NSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS

result:

wrong answer number of N:s not equal to k