Submission #211358

# Submission time Handle Problem Language Result Execution time Memory
211358 2020-03-20T07:57:26 Z socho Crocodile's Underground City (IOI11_crocodile) C++14
0 / 100
7 ms 5376 KB
#include "bits/stdc++.h"
using namespace std;
// #define endl '\n'
// #define int long long

int n, m;
const int MXN = 100005;
vector<pair<int, int> > adj[MXN];
bool ter[MXN], assign[MXN];
int dist[MXN];
int via[MXN];

#include "crocodile.h"

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
  
	n = N, m = M;
	for (int i=0; i<m; i++) {
		int a, b, w;
		a = R[i][0], b = R[i][1], w = L[i];
		adj[a].push_back(make_pair(b, w));
		adj[b].push_back(make_pair(a, w));
	}
	
	priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pro;
	vector<int> poss[MXN];
	bool done[MXN];
	
	for (int i=0; i<MXN; i++) dist[i] = INT_MAX;
	
	int k = K;
	for (int i=0; i<k; i++) {
		int x = P[i];
		ter[x] = true;
		dist[x] = 0;
		done[x] = true;
		pro.push(make_pair(0, x));
	}

	
	while (!pro.empty()) {
		
		int di = pro.top().first;
		int no = pro.top().second;
		pro.pop();
		
		if (dist[no] < di) continue; // do not relax

		if (poss[no].size() >= 2 && dist[no] == INT_MAX) {
			// can assign second dist, first relaxing
			done[no] = true;
			sort(poss[no].begin(), poss[no].end());
			dist[no] = poss[no][1];
		}
		
		if (done[no] && !assign[no]) {
			assign[no] = true;
			// can access adjs
			for (int i=0; i<adj[no].size(); i++) {
				// cout << "add option: " << no << " to " << adj[no][i].first << endl;
				int f = adj[no][i].second;
				pro.push(make_pair(f + dist[no], adj[no][i].first));
				poss[adj[no][i].first].push_back(f + dist[no]);
			}
		}

	}
	
	return dist[0];
  
}



Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:60:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i=0; i<adj[no].size(); i++) {
                  ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5376 KB Output is correct
2 Incorrect 7 ms 5376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5376 KB Output is correct
2 Incorrect 7 ms 5376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5376 KB Output is correct
2 Incorrect 7 ms 5376 KB Output isn't correct
3 Halted 0 ms 0 KB -