Submission #148122

# Submission time Handle Problem Language Result Execution time Memory
148122 2019-08-31T14:04:54 Z WhipppedCream Crocodile's Underground City (IOI11_crocodile) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define ii pair<int, int>
#define st first
#define nd second
#define maxn 100005
vector< ii > adj[maxn];
bool mark[maxn];
ii dist[maxn];
struct node
{
	int u, d;
	node(){}
	node(int _u, int _d)
	{
		u = _u;
		d = _d;
	}
	bool operator < (node other) const
	{
		return d> other.d;
	}
};
int travel_plan(int n, int m, int R[][2], int *L, int k, int *P)
{
    priority_queue< node > pq;
    for(int i = 0; i< n; i++)
    {
        dist[i].st = dist[i].nd = 1e9;
        pq.push(node(i, 1e9));
    }
	for(int i = 0; i< m; i++)
	{
		adj[R[i][0]].push_back(ii(R[i][1], L[i]));
		adj[R[i][1]].push_back(ii(R[i][0], L[i]));
	}
	for(int i = 0; i< k; i++)
	{
		pq.push(node(P[i], 0));
		dist[P[i]].st = dist[P[i]].nd = 0;
	}
	while(!pq.empty())
	{
		node x = pq.top();
		pq.pop();
		int u = x.u;
        printf("popped %d with %d\n", u, x.d);
        if(x.d != dist[u].nd) continue;
		for(int i = 0; i< (int) adj[u].size(); i++)
		{
			ii k = adj[u][i];
			int v = k.st, w = k.nd;
			int nw = w+dist[u].nd;
			if(nw < dist[v].st)
			{
				dist[v].nd = dist[v].st;
				dist[v].st = nw;
				pq.push(node(v, dist[v].nd));
			}
			else if(nw < dist[v].nd)
			{
				dist[v].nd = nw;
				pq.push(node(v, dist[v].nd));
			}
		}
        if(dist[0].nd != 1e9) printf("%d\n", dist[0].nd);
	}
	return dist[0].nd;
}

#define MAX_N 100005
#define MAX_M 1000005

int N, M;
int R[MAX_M][2];
int L[MAX_M];
int K;
int P[MAX_N];

void read_input()
{
  int i;
  scanf("%d %d %d",&N,&M,&K);
  for(i=0; i<M; i++)
    scanf("%d %d %d",&R[i][0],&R[i][1],&L[i]);
  for(i=0; i<K; i++)
    scanf("%d",&P[i]);
}

int main()
{
  int ans;
  read_input();
  ans = travel_plan(N,M,R,L,K,P);
  printf("%d\n", ans);
  return 0;
}

Compilation message

crocodile.cpp: In function 'void read_input()':
crocodile.cpp:83:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&N,&M,&K);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
crocodile.cpp:85:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d",&R[i][0],&R[i][1],&L[i]);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
crocodile.cpp:87:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&P[i]);
     ~~~~~^~~~~~~~~~~~
/tmp/ccNFNZZD.o: In function `read_input()':
grader.cpp:(.text+0x0): multiple definition of `read_input()'
/tmp/ccNekytQ.o:crocodile.cpp:(.text+0x30): first defined here
/tmp/ccNFNZZD.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccNekytQ.o:crocodile.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status