Submission #244553

# Submission time Handle Problem Language Result Execution time Memory
244553 2020-07-04T09:36:23 Z arnold518 Price List (POI13_cen) C++14
100 / 100
197 ms 14268 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2e5;
const ll INF = 1e15;

int N, M, K, A, B;
pii E[MAXN+10];
vector<int> adj[MAXN/2+10], adj2[MAXN/2+10];

ll dist1[MAXN+10], dist2[MAXN+10];
bool vis1[MAXN+10], vis2[MAXN+10];

struct Queue
{
	int v, w;
};

bool f(int u, int v) { return binary_search(adj2[u].begin(), adj2[u].end(), v); }

int main()
{
	int i, j;

	scanf("%d%d%d%d%d", &N, &M, &K, &A, &B);
	for(i=1; i<=M; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
		adj2[u].push_back(v);
		adj2[v].push_back(u);
	}
	for(i=1; i<=N; i++) sort(adj2[i].begin(), adj2[i].end());

	for(i=1; i<=N; i++) dist1[i]=dist2[i]=INF;
	queue<Queue> Q;
	Q.push({K, 0}); vis1[K]=1; dist1[K]=0;
	while(!Q.empty())
	{
		Queue now=Q.front(); Q.pop();
		for(auto nxt : adj[now.v])
		{
			if(vis1[nxt]) continue;
			dist1[nxt]=now.w+1;
			vis1[nxt]=true;
			Q.push({nxt, now.w+1});
		}
	}

	Q.push({K, 0}); vis2[K]=1; dist2[K]=0;
	while(!Q.empty())
	{
		Queue now=Q.front(); Q.pop();
		for(auto nxt : adj2[now.v])
		{
			for(auto nxt2 : adj[nxt])
			{
				if(vis2[nxt2]) continue;
				if(f(now.v, nxt2)) continue;
				Q.push({nxt2, now.w+1});
				dist2[nxt2]=now.w+1;
				vis2[nxt2]=true;
			}
			vector<int> V;
			for(auto nxt2 : adj[nxt]) if(!vis2[nxt2]) V.push_back(nxt2);
			swap(adj[nxt], V);
		}
	}

	for(i=1; i<=N; i++)
	{
		if(dist1[i]%2==0) printf("%lld\n", min(dist1[i]*A, dist1[i]/2*B));
		else printf("%lld\n", min({dist1[i]*A, dist1[i]/2*B+A, dist2[i]*B}));
	}
}

Compilation message

cen.cpp: In function 'int main()':
cen.cpp:27:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
cen.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d%d", &N, &M, &K, &A, &B);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cen.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &u, &v);
   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4992 KB Output is correct
2 Correct 7 ms 4992 KB Output is correct
3 Correct 7 ms 4992 KB Output is correct
4 Correct 9 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4992 KB Output is correct
2 Correct 7 ms 4992 KB Output is correct
3 Correct 7 ms 4992 KB Output is correct
4 Correct 8 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5120 KB Output is correct
2 Correct 8 ms 5120 KB Output is correct
3 Correct 8 ms 5120 KB Output is correct
4 Correct 8 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 6144 KB Output is correct
2 Correct 17 ms 6144 KB Output is correct
3 Correct 21 ms 6144 KB Output is correct
4 Correct 30 ms 6136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 8744 KB Output is correct
2 Correct 41 ms 8744 KB Output is correct
3 Correct 41 ms 7672 KB Output is correct
4 Correct 55 ms 8568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 11432 KB Output is correct
2 Correct 61 ms 10616 KB Output is correct
3 Correct 158 ms 11384 KB Output is correct
4 Correct 124 ms 11128 KB Output is correct
5 Correct 75 ms 11876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 12692 KB Output is correct
2 Correct 67 ms 10872 KB Output is correct
3 Correct 134 ms 11476 KB Output is correct
4 Correct 124 ms 11128 KB Output is correct
5 Correct 97 ms 12812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 13992 KB Output is correct
2 Correct 106 ms 13176 KB Output is correct
3 Correct 144 ms 12152 KB Output is correct
4 Correct 119 ms 11128 KB Output is correct
5 Correct 105 ms 13640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 13432 KB Output is correct
2 Correct 110 ms 13560 KB Output is correct
3 Correct 161 ms 12536 KB Output is correct
4 Correct 146 ms 11376 KB Output is correct
5 Correct 120 ms 14268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 13816 KB Output is correct
2 Correct 132 ms 13816 KB Output is correct
3 Correct 197 ms 13816 KB Output is correct
4 Correct 119 ms 11256 KB Output is correct
5 Correct 112 ms 14260 KB Output is correct