Submission #42497

# Submission time Handle Problem Language Result Execution time Memory
42497 2018-02-27T22:15:20 Z MatheusLealV Evacuation plan (IZhO18_plan) C++14
0 / 100
798 ms 34704 KB
#include <bits/stdc++.h>
#define int long long
#define N 100005
#define inf 2000000000000000000LL
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int n, m, k, q, P[N], id[N], dist[N], rev[N];

vector<pii> grafo[N];

void dijkstra()
{
	priority_queue<pii, vector<pii>, greater<pii> > pq;

	for(int i = 1; i <= n; i++) dist[i] = inf;

	for(int i = 1; i <= k; i++) dist[ P[i] ] = 0, pq.push({0, P[i]});

	while(!pq.empty())
	{
		int x = pq.top().s, d = pq.top().f;

		pq.pop();

		if(d > dist[x]) continue;

		for(auto v: grafo[x])
		{
			if(dist[v.f] > dist[x] + v.s)
			{
				dist[v.f] = dist[x] + v.s;

				pq.push({dist[v.f], v.f});
			}
		}
	}

	vector<pii> v;

	for(int i = 1; i <= n; i++) v.push_back({dist[i], i});

	sort(v.begin(), v.end());

	for(int i = 0; i < v.size(); i++) id[ v[i].s ] = i + 1, rev[i + 1] = v[i].s;
}

int ok[N];

void dfs(int x, int limite, int c)
{
	ok[x] = c;

	for(auto v: grafo[x])
	{
		if(!ok[v.f] && id[v.f] >= limite) dfs(v.f, limite, c);
	}
}

int cor = 1;

int32_t main()
{
	ios::sync_with_stdio(false); cin.tie(0);

	cin>>n>>m;

	for(int i = 1, a, b, c; i <= m; i++)
	{
		cin>>a>>b>>c;

		grafo[a].push_back({b, c});

		grafo[b].push_back({a, c});
	}

	cin>>k;

	for(int i = 1; i <= k; i++) cin>>P[i];

	dijkstra();

	cin>>q;

	for(int t = 1, a, b; t <= q; t++)
	{
		cin>>a>>b;

		int ini = 1, fim = n, mid, best = -1;

		while(fim >= ini)
		{
			mid = (ini + fim)/2;

			memset(ok, 0, sizeof ok);

			for(int x = 1; x <= n; x++)
			{
				if(!ok[x] && id[x] >= mid)
				{
					dfs(x, mid, ++cor);
				}
			}

			if(ok[a] == ok[b]) best = mid, ini = mid + 1;

			else fim = mid - 1;
		}

		cout<<dist[ rev[best] ]<<"\n";
	}
}

Compilation message

plan.cpp: In function 'void dijkstra()':
plan.cpp:48:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < v.size(); i++) id[ v[i].s ] = i + 1, rev[i + 1] = v[i].s;
                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 3464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 3464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 3536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 355 ms 18600 KB Output is correct
2 Correct 798 ms 34704 KB Output is correct
3 Incorrect 514 ms 34572 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 3464 KB Output isn't correct
2 Halted 0 ms 0 KB -