답안 #28437

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28437 2017-07-16T05:52:09 Z 점수판에 아이디와 팀명이 같이 표기되니, 신중하게 적어주세요.(#1186, kajebiii, secsegy, woqja125) Alternative Mart (FXCUP2_mart) C++14
1 / 1
1096 ms 43152 KB
#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi; typedef pair<ll, int> pli; typedef pair<ll, pi> plp;
typedef tuple<int, int, int> ti; typedef tuple<ll, int, int> tli;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 5e4 + 100;

int N, M, K, Qn;
vector<int> Ks;
vector<pi> Ed[MAX_N];
int Chk[MAX_N];
int main() {
	cin >> N >> M >> K >> Qn;
	for(int i=0; i<K; i++) {int x; scanf("%d", &x); x--; Ks.push_back(x);}
	for(int i=0; i<M; i++) {
		int x, y, c; scanf("%d%d%d", &x, &y, &c); x--; y--;
		Ed[x].push_back(pi(y, c));
		Ed[y].push_back(pi(x, c));
	}
	vector<vector<pi>> dis(11, vector<pi>(N, pi(INF, -1)));
	vector<vector<int>> mar(N, vector<int>());
	vector<int> cnt(N, 0);
	priority_queue<ti, vector<ti>, greater<ti>> Q;
	for(int k : Ks) {
		Q.push(ti(0, k, k));
		dis[0][k] = pi(0, k);
	}
	while(!Q.empty()) {
		int d, v, wh; tie(d, v, wh) = Q.top(); Q.pop();
		if(cnt[v] >= 11) continue;
		bool isCan = true; for(int i=0; i<cnt[v]; i++) if(mar[v][i] == wh) {isCan = false; break;}
		if(!isCan) continue;
//		printf("%d %d %d\n", d, v, wh);
		mar[v].push_back(wh);
		dis[cnt[v]][v] = pi(d, wh); cnt[v]++;

		for(pi &e : Ed[v]) {
			int w, c; tie(w, c) = e;
			if(cnt[w] >= 11) continue;
			Q.push(ti(d+c, w, wh));
//			printf("push %d %d %d\n", d+c, w, wh);
		}
	}

	for(int q=1; q<=Qn; q++) {
		int s, k;
		scanf("%d%d", &s, &k); s--;
		for(int i=0; i<k; i++) {
			int x; scanf("%d", &x); x--;
			Chk[x] = q;
		}
		for(int i=0; i<11; i++) {
			if(Chk[mar[s][i]] != q) {
				printf("%d %d\n", dis[i][s].two+1, dis[i][s].one);
				break;
			}
		}
	}
	return 0;
}

Compilation message

mart.cpp: In function 'int main()':
mart.cpp:24:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0; i<K; i++) {int x; scanf("%d", &x); x--; Ks.push_back(x);}
                                                ^
mart.cpp:26:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y, c; scanf("%d%d%d", &x, &y, &c); x--; y--;
                                           ^
mart.cpp:57:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &s, &k); s--;
                        ^
mart.cpp:59:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int x; scanf("%d", &x); x--;
                          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3392 KB Output is correct
2 Correct 0 ms 3392 KB Output is correct
3 Correct 0 ms 3392 KB Output is correct
4 Correct 0 ms 3392 KB Output is correct
5 Correct 0 ms 3528 KB Output is correct
6 Correct 0 ms 3528 KB Output is correct
7 Correct 3 ms 3524 KB Output is correct
8 Correct 3 ms 3524 KB Output is correct
9 Correct 49 ms 8432 KB Output is correct
10 Correct 46 ms 8428 KB Output is correct
11 Correct 39 ms 4784 KB Output is correct
12 Correct 33 ms 4608 KB Output is correct
13 Correct 523 ms 43152 KB Output is correct
14 Correct 516 ms 43148 KB Output is correct
15 Correct 123 ms 12728 KB Output is correct
16 Correct 109 ms 12164 KB Output is correct
17 Correct 626 ms 16860 KB Output is correct
18 Correct 439 ms 15068 KB Output is correct
19 Correct 566 ms 16724 KB Output is correct
20 Correct 493 ms 15200 KB Output is correct
21 Correct 589 ms 16856 KB Output is correct
22 Correct 563 ms 15376 KB Output is correct
23 Correct 539 ms 18708 KB Output is correct
24 Correct 753 ms 18536 KB Output is correct
25 Correct 666 ms 22744 KB Output is correct
26 Correct 796 ms 18672 KB Output is correct
27 Correct 149 ms 13564 KB Output is correct
28 Correct 143 ms 12836 KB Output is correct
29 Correct 969 ms 18888 KB Output is correct
30 Correct 736 ms 16892 KB Output is correct
31 Correct 749 ms 18456 KB Output is correct
32 Correct 703 ms 16672 KB Output is correct
33 Correct 719 ms 18436 KB Output is correct
34 Correct 863 ms 22284 KB Output is correct
35 Correct 679 ms 22376 KB Output is correct
36 Correct 876 ms 22408 KB Output is correct
37 Correct 896 ms 22436 KB Output is correct
38 Correct 886 ms 22456 KB Output is correct
39 Correct 153 ms 13820 KB Output is correct
40 Correct 173 ms 13820 KB Output is correct
41 Correct 1096 ms 22216 KB Output is correct
42 Correct 1073 ms 22408 KB Output is correct
43 Correct 929 ms 22088 KB Output is correct
44 Correct 979 ms 22148 KB Output is correct
45 Correct 949 ms 22108 KB Output is correct
46 Correct 966 ms 22176 KB Output is correct
47 Correct 816 ms 32432 KB Output is correct
48 Correct 1066 ms 32728 KB Output is correct
49 Correct 1006 ms 32572 KB Output is correct
50 Correct 1046 ms 32728 KB Output is correct
51 Correct 816 ms 32168 KB Output is correct
52 Correct 799 ms 32200 KB Output is correct
53 Correct 386 ms 14540 KB Output is correct
54 Correct 689 ms 22448 KB Output is correct
55 Correct 736 ms 21916 KB Output is correct
56 Correct 689 ms 22044 KB Output is correct
57 Correct 513 ms 42556 KB Output is correct