답안 #28708

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28708 2017-07-16T08:55:18 Z 슈퍼스타 tlwpdus(#1124, tlwpdus) Alternative Mart (FXCUP2_mart) C++11
0 / 1
5000 ms 163924 KB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int,int> pii;

int n, m, k, q;
vector<int> mart;
vector<pii> lis[50010];

map<pii,int> fin;
pii rin[3000000];
int p;
int dis[3000000];
int cnt[50010];
vector<pii> gd[50010];

int msv = 15;

void dijk() {
	int i;
	priority_queue<pii> pq;

	for (i=0;i<3000000;i++) dis[i] = 987654321;
	for (i=0;i<k;i++) {
		fin[pii(mart[i],mart[i])] = p;
		rin[p] = pii(mart[i],mart[i]);
		dis[p] = 0;
		pq.push(pii(0,p));
		p++;
	}

	while(!pq.empty()) {
		pii tmp = pq.top(); pq.pop();
		if (dis[tmp.second]!=-tmp.first||cnt[rin[tmp.second].first]>=msv) continue;
		int here = rin[tmp.second].first, mar = rin[tmp.second].second, d = -tmp.first;
		cnt[here]++;
		for (auto &tmp : lis[here]) {
			int there = tmp.second, w = tmp.first;
			if (cnt[there]>=msv) continue;
			auto it = fin.find(pii(there,mar));
			int curp;
			if (it==fin.end()) {
				curp = p;
				fin[pii(there,mar)] = p;
				rin[p] = pii(there,mar);
				p++;
			}
			else curp = it->second;
			if (dis[curp]<=d+w) continue;
			dis[curp] = d+w;
			pq.push(pii(-d-w,curp));
		}
	}
	for (i=0;i<p;i++) gd[rin[i].first].push_back(pii(dis[i],rin[i].second));
	for (i=0;i<n;i++) sort(gd[i].begin(),gd[i].end());
}

vector<int> que;
bool qchk[50010];
int main() {
	int i, j;

	scanf("%d%d%d%d",&n,&m,&k,&q);
	for (i=0;i<k;i++) {
		int a;
		scanf("%d",&a); --a;
		mart.push_back(a);
	}
	for (i=0;i<m;i++) {
		int a, b, c;
		scanf("%d%d%d",&a,&b,&c); --a; --b;
		lis[a].push_back(pii(c,b));
		lis[b].push_back(pii(c,a));
	}
	dijk();
	que.reserve(12);
	for (i=0;i<q;i++) {
		int s, x;
		scanf("%d%d",&s,&x); --s;
		for (int j=0;j<x;j++) {
			int a;
			scanf("%d",&a); --a;
			que.push_back(a);
			qchk[a] = 1;
		}
		for (j=0;j<gd[s].size();j++) {
			if (!qchk[gd[s][j].second]) {
				printf("%d %d\n",gd[s][j].second+1,gd[s][j].first);
				break;
			}
		}
		for (int j=0;j<x;j++) {
			qchk[que[j]] = 0;
		}
		que.clear();
	}

    return 0;
}

Compilation message

mart.cpp: In function 'int main()':
mart.cpp:87:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (j=0;j<gd[s].size();j++) {
             ^
mart.cpp:64:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d",&n,&m,&k,&q);
                               ^
mart.cpp:67:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a); --a;
                 ^
mart.cpp:72:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d",&a,&b,&c); --a; --b;
                           ^
mart.cpp:80:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&s,&x); --s;
                      ^
mart.cpp:83:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&a); --a;
                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 39772 KB Output is correct
2 Correct 3 ms 39772 KB Output is correct
3 Correct 9 ms 39772 KB Output is correct
4 Correct 6 ms 39772 KB Output is correct
5 Correct 3 ms 39904 KB Output is correct
6 Correct 3 ms 39772 KB Output is correct
7 Correct 9 ms 40432 KB Output is correct
8 Correct 6 ms 40436 KB Output is correct
9 Correct 166 ms 44536 KB Output is correct
10 Correct 39 ms 40432 KB Output is correct
11 Correct 109 ms 45580 KB Output is correct
12 Correct 133 ms 45448 KB Output is correct
13 Correct 3906 ms 116796 KB Output is correct
14 Correct 4786 ms 163924 KB Output is correct
15 Correct 183 ms 46372 KB Output is correct
16 Correct 146 ms 45976 KB Output is correct
17 Correct 1826 ms 80944 KB Output is correct
18 Correct 1223 ms 80428 KB Output is correct
19 Correct 2506 ms 96972 KB Output is correct
20 Correct 2219 ms 96136 KB Output is correct
21 Correct 2359 ms 97336 KB Output is correct
22 Correct 2676 ms 96140 KB Output is correct
23 Correct 2736 ms 103472 KB Output is correct
24 Correct 2966 ms 102804 KB Output is correct
25 Correct 2873 ms 105320 KB Output is correct
26 Correct 3139 ms 106104 KB Output is correct
27 Correct 199 ms 46672 KB Output is correct
28 Correct 203 ms 46376 KB Output is correct
29 Correct 2209 ms 82008 KB Output is correct
30 Correct 1906 ms 81080 KB Output is correct
31 Correct 3009 ms 110068 KB Output is correct
32 Correct 2976 ms 103156 KB Output is correct
33 Correct 2913 ms 107956 KB Output is correct
34 Correct 4336 ms 136444 KB Output is correct
35 Correct 3466 ms 121520 KB Output is correct
36 Correct 4099 ms 133532 KB Output is correct
37 Correct 4373 ms 146908 KB Output is correct
38 Correct 4416 ms 138344 KB Output is correct
39 Correct 233 ms 47160 KB Output is correct
40 Correct 276 ms 47164 KB Output is correct
41 Correct 2573 ms 83404 KB Output is correct
42 Correct 2659 ms 83408 KB Output is correct
43 Correct 4813 ms 136404 KB Output is correct
44 Execution timed out 5000 ms 139440 KB Execution timed out
45 Halted 0 ms 0 KB -