Submission #18257

# Submission time Handle Problem Language Result Execution time Memory
18257 2016-01-26T02:44:38 Z tlwpdus Sightseeing (NOI14_sightseeing) C++
Compilation error
0 ms 0 KB
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

struct edge{
	int i, j, w;
	edge(int i, int j, int w):i(i),j(j),w(w){}
	edge(){}
	inline bool operator < (const edge &A) const {return w<A.w;}
};

vector<edge> lis[500100];
int n, m, q;
int ans[500100];
priority_queue<edge> pq;

const int INF = 1e9;

void prim() {
	int i;
	memset(ans,-1,sizeof(ans));
	ans[0] = INF;
	for (i=0;i<lis[0].size();i++) pq.push(lis[0][i]);
	while(!pq.empty()) {
		edge te = pq.top();
		pq.pop();
		if (ans[te.j]!=-1) continue;
		int here = te.j;
		ans[here] = min(ans[te.i],te.w);
		for (i = 0;i<lis[here].size();i++) pq.push(lis[here][i]);
	}
}

void process() {
	int i;
	prim();
	for (i=0;i<q;i++) {
		int a;
		scanf("%d",&a);
		--a;
		printf("%d\n",ans[a]);
	}
}

void input() {
	int i;
	scanf("%d %d %d",&n,&m,&q);
	for (i=0;i<m;i++) {
		int a, b, w;
		scanf("%d %d %d",&a,&b,&w);
		--a;--b;
		lis[a].push_back(edge(a,b,w));
		lis[b].push_back(edge(b,a,w));
	}
}

int main() {
	input();
	process();
	return 0;
}

Compilation message

sightseeing.cpp: In function ‘void prim()’:
sightseeing.cpp:24:27: error: ‘memset’ was not declared in this scope
  memset(ans,-1,sizeof(ans));
                           ^
sightseeing.cpp:26:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i=0;i<lis[0].size();i++) pq.push(lis[0][i]);
            ^
sightseeing.cpp:33:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (i = 0;i<lis[here].size();i++) pq.push(lis[here][i]);
               ^
sightseeing.cpp: In function ‘void process()’:
sightseeing.cpp:42:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a);
                 ^
sightseeing.cpp: In function ‘void input()’:
sightseeing.cpp:50:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n,&m,&q);
                            ^
sightseeing.cpp:53:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&a,&b,&w);
                             ^