QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#58360#1774. Customs ControlsyzasaaaWA 3ms16032kbC++2.6kb2022-10-26 01:03:252022-10-26 01:03: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-10-26 01:03:28]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:16032kb
  • [2022-10-26 01:03:25]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N=100010,M=100010*5;
int head[N],ver[M],edge[M],nxt[M],d[N],t[N];
int head2[N],ver2[M],nxt2[M];
bool v[N];
int n,m,k,tot,tot2;
priority_queue< pair<int,int> >q;
vector<int> pre[N];
vector<int> tmppath;
queue<int> q2;
int rudu[N],topperxu[N],num;
char ans[N];

void add(int x,int y,int z){
	ver[++tot] = y,edge[tot] = z,nxt[tot] = head[x],head[x] = tot;
}

void add2(int x,int y){
	ver2[++tot2] = y,nxt2[tot2] = head2[x],head2[x] = tot2;
}

void dfs(int v) {
	if(v == 1) {
    	tmppath.push_back(v);
    	//for(int i = tmppath.size() - 1; i >= 0; i--)
		    //printf("%d ", tmppath[i]);
		//printf("\n");
		//½«ËùÓпÉÄܵÄ×î¶Ì·¹¹ÔìÓÐÏòÎÞ»·Í¼
		int siz = tmppath.size();
		for(int i=siz-1;i>0;--i){
			add2(tmppath[i],tmppath[i-1]);
			rudu[tmppath[i-1]]++;
		}
    	tmppath.pop_back();
    	return;
  	}
  	tmppath.push_back(v);
  	for(int i = 0; i < (int)pre[v].size(); i++){
	  	dfs(pre[v][i]);
	}
  	tmppath.pop_back();
}


void dijkstra(){
	memset(d,0x3f,sizeof(d));
	memset(v,0,sizeof(v));
	d[1] = 0;
	q.push(make_pair(0,1));
	while(q.size()){
		int x = q.top().second;
		q.pop();
		if(v[x]) continue;
		v[x] = 1;
		for(int i=head[x];i;i=nxt[i]){
			int y = ver[i],z=edge[i];
			if(d[y]>d[x]+z){
				d[y] = d[x]+z;
				q.push(make_pair(-d[y],y));
				pre[y].clear();
				pre[y].push_back(x);
			}else{
				if(d[y]==d[x]+z){
					pre[y].push_back(x);
				}
			}
		}
	}
}

void topsort(){
	q2.push(1);
	while(!q2.empty()){
		int u = q2.front();
		q2.pop();
		for(int i=head2[u];i;i=nxt2[i]){
			int v = ver2[i];
			if(--rudu[v]==0) q2.push(v);
		}
		topperxu[++num] = u;
		//printf("%d ",u);
	}
}

int main() {
	scanf("%d%d%d",&n,&m,&k);
	if(n==2&&k==1){
		printf("impossible");
		return 0;
	}
	for(int i=1;i<=n;++i){
		scanf("%d",&t[i]);
	}
	for(int i=1;i<=m;++i){
		int x,y,z;
		scanf("%d%d",&x,&y);
		z = t[y];
		add(x,y,z);
		add(y,x,t[x]);
	}
	dijkstra();
	dfs(n);
	topsort();
	//1ºÍnÖ±½ÓÏàÁ¬
	if(num==2){
		if(k>=num){
			ans[1] = ans[n] = 1;
			int tt = 2;
			for(int i=2;i<n&&tt<=k;++i){
				ans[i] = 1;
				++tt;
				if(tt==k) break;
			}
		}else{
			if(k==1) ans[2] = 1;
		}
	}else{
		if(k>num){
			for(int i=1;i<=num;++i) ans[topperxu[i]] = 1;//±íʾU
			int tt = num;
			for(int i=1;i<=n&&tt<=k;++i){
				if(!ans[i]){
					ans[i] = 1;
					++tt;
				}
				if(tt==k) break;
			}
		}else{
			for(int i=1;i<=k;++i) ans[topperxu[i]] = 1;
		}
	}
	for(int i=1;i<=n;++i){
		printf("%c",ans[i]==1 ? 'N' : 'S');
	}
    return 0;
}

詳細信息

Test #1:

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

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:

NNSSN

result:

wrong answer number of N:s not equal to k