QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202069#1774. Customs Controlsdog_of_zimuWA 1ms7620kbC++143.2kb2023-10-05 19:00:192023-10-05 19:00:20

Judging History

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

  • [2023-10-05 19:00:20]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7620kb
  • [2023-10-05 19:00:19]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<queue>
#include<random>
#include<ctime>
using namespace std;
namespace LZZMD{
	const int N = 1e5, M = 2e5, inf = 0x7fffffff / 2;
	struct edge{
		int nxt, to;
	} e[M * 6 + 10];
	int head[N * 3 + 10], cnt;
	int time[N + 10];
	int n, m, k;
	inline void add(int u, int v){
		e[++cnt] = {head[u], v};
		head[u] = cnt;
	}
	struct node{
		int u, dis;
	};
	priority_queue<node> q;
	bool operator < (node x, node y){
		return x.dis > y.dis;
	}
	int dis[N + 10], vis[N + 10];
	inline void dijkstra(int s){
		for(int i = 1; i <= n; i++)
			dis[i] = inf;
		dis[s] = time[s];
		q.push({s, dis[s]});
		while(q.size()){
			int u = q.top().u;
			q.pop();
			if(vis[u])
				continue;
			vis[u] = 1;
			for(int i = head[u]; i; i = e[i].nxt){
				int v = e[i].to;
				if(dis[v] > dis[u] + time[v]){
					dis[v] = dis[u] + time[v];
					q.push({v, dis[v]});
				}
			}
		}
	}
	bool ans[N + 10];
	int f[N + 10]; 
	void dfs(int u){
		f[u - n] = 1;
		for(int i = head[u]; i; i = e[i].nxt){
			dfs(e[i].to);
			f[u - n] += f[e[i].to - n];
		}
	}
	int main(){
		if(rand() & 1){
			scanf("%d%d%d", &n, &m, &k);
			for(int i = 1; i <= n; i++)
				scanf("%d", &time[i]);
			for(int i = 1, u, v; i <= m; i++){
				scanf("%d%d", &u, &v);
				add(u, v), add(v, u);
			}
			dijkstra(1);
			for(int u = 1; u <= n; u++)
				for(int i = head[u]; i; i = e[i].nxt)
					if(dis[e[i].to] + time[u] == dis[u])
						add(e[i].to + n, u + n);
			dfs(n + 1);
			priority_queue<pair<int, int> > pq;
			for(int i = head[1]; i; i = e[i].nxt){
				int v = e[i].to;
				pq.push({f[v], v});
			}
			int s = 0;
			if(k){
				s++;
				ans[1] = 1;
				while(pq.size() && s < k)
					ans[pq.top().second] = 1, pq.pop(), s++;
			}
			for(int i = 1; i <= n; i++){
				for(int j = head[i]; j; j = e[j].nxt)
					if(e[j].to == n)
						goto ZZM;
				if(!ans[i] && s < k)
					ans[i] = 1, s++;
				ZZM:;
			}
			for(int i = 1; i <= n; i++){
				if(!ans[i] && s < k)
					ans[i] = 1, s++;
				putchar(ans[i] ? 'N' : 'S');
			}
		}
		else{
			scanf("%lld%lld%lld", &n, &m, &k);
			for(int i = 1; i <= n; i++)
				scanf("%lld", &time[i]);
			for(int i = 1, u, v; i <= m; i++){
				scanf("%lld%lld", &u, &v);
				add(u, v), add(v, u);
			}
			dijkstra(1);
			int s1 = 1, s2 = 1;
			for(int i = head[1]; i; i = e[i].nxt)
				if(dis[1] + time[e[i].to] == dis[e[i].to])
					s1++;
			for(int i = head[n]; i; i = e[i].nxt)
				if(dis[e[i].to] + time[n] == dis[n])
					s2++;
			int tmp;
			if(s1 <= s2){
				tmp = s1;
				ans[1] = 1;
				for(int i = head[1]; i; i = e[i].nxt)
					if(dis[1] + time[e[i].to] == dis[e[i].to])
						ans[e[i].to] = 1;
			}
			else{
				tmp = s2;
				ans[n] = 1;
				for(int i = head[n]; i; i = e[i].nxt)
					if(dis[e[i].to] + time[n] == dis[n])
						ans[e[i].to] = 1;
			}
			int flag = 0;
			if(k < n - k)
				k = n - k, flag = 1;
			for(int i = 1; i <= n; i++){
				if(!ans[i] && tmp < k)
					ans[i] = 1, tmp++;
				if(!flag)
					putchar(ans[i] ? 'N' : 'S');
				else
					putchar(ans[i] ? 'S' : 'N');
			}
		}
		return 0;
	}
}
int main(){
	srand(time(0));
	return LZZMD::main();
}
//14MB

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3668kb

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

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:

NNSSSSNNSN

result:

ok accepted

Test #3:

score: 0
Accepted
time: 1ms
memory: 3612kb

input:

2 1 2
6124 7094
2 1

output:

NN

result:

ok accepted

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 7620kb

input:

2 1 1
6901 1417
2 1

output:

NS

result:

wrong answer an alternating shortest path existed