Submission #815516

# Submission time Handle Problem Language Result Execution time Memory
815516 2023-08-08T16:23:34 Z OAleksa Crocodile's Underground City (IOI11_crocodile) C++14
0 / 100
3 ms 5332 KB
#include <bits/stdc++.h>
//#include "factories.h"
#include "crocodile.h"
#define f first
#define s second
using namespace std; 
const int maxn = 1e5 + 69;
set<pair<int, int>> g[maxn];
vector<int> cnt(maxn);
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
  	for(int i = 0;i < M;i++) {
  		g[R[i][0]].insert({L[i], R[i][1]});
  		g[R[i][1]].insert({L[i], R[i][0]});
  	}
  	for(int i = 0;i < K;i++)
		cnt[P[i]] = 1;
	for(int i = 1;i < N;i++) {
		if(cnt[i])
			continue;
		if(g[i].size() == 2 && !cnt[i]) {
			for(auto x : g[i]) 
				g[x.s].erase({x.f, i});
			g[i].clear();
		}
	}
	for(int i = 0;i < N;i++) {
		if(g[i].size() >= 2 && !cnt[i]) {
			auto x = *g[i].begin();
			g[i].erase(x);
			g[x.s].erase({x.f, i});
		}
	}
	// for(int i = 0;i < N;i++) {
		// cout << i << endl;
		// for(auto x : g[i]) {
			// cout << x.f << " " << x.s << endl;
		// }
		// cout << endl;
	// }
	priority_queue<pair<int, int>> pq;
	pq.push({0, 0});
	vector<int> d(N, 1e9);
	d[0] = 0;
	while(!pq.empty()) {
		auto u = pq.top();
		pq.pop();
		for(auto v : g[u.s]) {
			if(d[v.s] <= d[u.s] + v.f)
				continue;
			d[v.s] = d[u.s] + v.f;
			pq.push({-d[v.s], v.s});
		}
	}
	int ans = 1e9;
	for(int i = 1;i < N;i++) {
		if(cnt[i])
			ans = min(ans, d[i]);
	}
	return ans;
}



// int main()
// {
	// ios_base::sync_with_stdio(false);
	// cin.tie(0);
	// cout.tie(0);
	// int tt = 1;
	// //cin >> tt;
	// while(tt--) {
		// int n, m;
		// cin >> n >> m;
		// int r[m][2];
		// for(int i = 0;i < m;i++)
			// cin >> r[i][0] >> r[i][1];
		// int l[m];
		// for(int i = 0;i < m;i++)
			// cin >> l[i];
		// int k;
		// cin >> k;
		// int p[k];
		// for(int i = 0;i < k;i++)
			// cin >> p[i];
		// cout << travel_plan(n, m, r, l, k, p);
	// }
   // return 0;
// }
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5332 KB Output is correct
2 Incorrect 3 ms 5332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5332 KB Output is correct
2 Incorrect 3 ms 5332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5332 KB Output is correct
2 Incorrect 3 ms 5332 KB Output isn't correct
3 Halted 0 ms 0 KB -