Submission #28659

# Submission time Handle Problem Language Result Execution time Memory
28659 2017-07-16T08:28:56 Z 슈퍼스타 tlwpdus(#1124, tlwpdus) Alternative Mart (FXCUP2_mart) C++11
0 / 1
3856 ms 132024 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[2600000];
int p;
int dis[2600000];
int cnt[50010];
vector<int> what[50010];
vector<pii> gd[50010];

int msv = 11;

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

	for (i=0;i<2600000;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++) {
		what[rin[i].first].push_back(rin[i].second);
	}

	for (i=0;i<n;i++) {
		sort(what[i].begin(),what[i].end());
		what[i].erase(unique(what[i].begin(),what[i].end()),what[i].end());
		for (int j=0;j<what[i].size();j++) {
			gd[i].push_back(pii(dis[fin[pii(i,what[i][j])]],what[i][j]));
		}
		sort(gd[i].begin(),gd[i].end());
		if (gd[i].size()<min(msv,k)) {
			while(true) {
				printf("!");
			}
		}
	}
}

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

	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 (int 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 'void dijk()':
mart.cpp:64:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j=0;j<what[i].size();j++) {
                 ^
mart.cpp:68:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (gd[i].size()<min(msv,k)) {
                   ^
mart.cpp:22:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
mart.cpp: In function 'int main()':
mart.cpp:104:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j=0;j<gd[s].size();j++) {
                 ^
mart.cpp:81: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:84:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a); --a;
                 ^
mart.cpp:89: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:97: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:100:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&a); --a;
                  ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 36260 KB Output is correct
2 Correct 6 ms 36260 KB Output is correct
3 Correct 0 ms 36260 KB Output is correct
4 Correct 3 ms 36260 KB Output is correct
5 Correct 3 ms 36392 KB Output is correct
6 Correct 6 ms 36392 KB Output is correct
7 Correct 9 ms 36788 KB Output is correct
8 Correct 3 ms 36788 KB Output is correct
9 Correct 123 ms 41156 KB Output is correct
10 Correct 39 ms 36920 KB Output is correct
11 Correct 66 ms 41144 KB Output is correct
12 Correct 106 ms 41012 KB Output is correct
13 Correct 2779 ms 106552 KB Output is correct
14 Correct 3856 ms 132024 KB Output is correct
15 Correct 153 ms 44444 KB Output is correct
16 Correct 146 ms 44048 KB Output is correct
17 Correct 1946 ms 81260 KB Output is correct
18 Correct 1329 ms 80480 KB Output is correct
19 Correct 1909 ms 84748 KB Output is correct
20 Correct 1863 ms 83780 KB Output is correct
21 Correct 1903 ms 85112 KB Output is correct
22 Correct 2193 ms 83916 KB Output is correct
23 Correct 2176 ms 90720 KB Output is correct
24 Correct 2259 ms 88204 KB Output is correct
25 Correct 2083 ms 92436 KB Output is correct
26 Correct 2376 ms 89788 KB Output is correct
27 Correct 193 ms 44744 KB Output is correct
28 Correct 193 ms 44448 KB Output is correct
29 Correct 2466 ms 82192 KB Output is correct
30 Correct 2093 ms 81264 KB Output is correct
31 Correct 2363 ms 94940 KB Output is correct
32 Correct 2516 ms 87500 KB Output is correct
33 Correct 2296 ms 92960 KB Output is correct
34 Correct 3286 ms 114452 KB Output is correct
35 Correct 2749 ms 105072 KB Output is correct
36 Correct 3146 ms 112860 KB Output is correct
37 Correct 3409 ms 122008 KB Output is correct
38 Correct 3736 ms 117276 KB Output is correct
39 Correct 283 ms 45232 KB Output is correct
40 Correct 256 ms 45104 KB Output is correct
41 Correct 3149 ms 83588 KB Output is correct
42 Correct 3063 ms 83724 KB Output is correct
43 Incorrect 3609 ms 117448 KB Output isn't correct
44 Halted 0 ms 0 KB -