답안 #28702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28702 2017-07-16T08:51:58 Z tlwpdus 팬클럽 회장(#1123, kdh9949) Alternative Mart (FXCUP2_mart) C++14
0 / 1
5000 ms 40284 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;

struct Dat{
	int s, x, d;
	bool operator<(const Dat &oth) const {
		return (d == oth.d) ? (s > oth.s) : (d > oth.d);
	}
};

const int inf = 1e9;
int n, m, k, q, chk[50010];
set<pii> md[50010];
vector<pii> e[50010];
priority_queue<Dat> pq;

int main(){
	scanf("%d%d%d%d", &n, &m, &k, &q);
	for(int i = 1, x; i <= k; i++){
		scanf("%d", &x);
		md[x].insert(pii(0, x));
		pq.push({x, x, 0});
	}
	for(int x, y, c; m--; ){
		scanf("%d%d%d", &x, &y, &c);
		e[x].push_back({y, c});
		e[y].push_back({x, c});
	}
	while(!pq.empty()){
		Dat c = pq.top(); pq.pop();
		for(auto &i : e[c.x]){
			int nx, nd; tie(nx, nd) = i;
			nd += c.d;
			int fl = 1;
			for(auto &i : md[nx]){
				if(i.second == c.s && i.first <= nd){ fl = 0; break; }
			}
			if(!fl) continue;
			for(auto &i : md[nx]){
				if(i.second == c.s){
					md[nx].erase(i);
					break;
				}
			}
			md[nx].insert(pii(nd, c.s));
			while(md[nx].size() > 11){
				auto t = md[nx].end();
				t--;
				md[nx].erase(t);
			}
			auto t = md[nx].end(); t--;
			if(nd <= t->first) pq.push({c.s, nx, nd});
		}
	}
	for(int i = 1, x, c; i <= q; i++){
		scanf("%d%d", &x, &c);
		for(int y; c--; ){
			scanf("%d", &y);
			chk[y] = i;
		}
		for(auto &j : md[x]){
			if(chk[j.second] == i) continue;
			printf("%d %d\n", j.second, j.first);
			break;
		}
	}
}

Compilation message

mart.cpp: In function 'int main()':
mart.cpp:19:35: 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:21:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &x);
                  ^
mart.cpp:26:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &x, &y, &c);
                              ^
mart.cpp:57:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &x, &c);
                        ^
mart.cpp:59:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &y);
                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5740 KB Output is correct
2 Correct 0 ms 5740 KB Output is correct
3 Correct 0 ms 5740 KB Output is correct
4 Correct 0 ms 5740 KB Output is correct
5 Correct 0 ms 5740 KB Output is correct
6 Correct 0 ms 5740 KB Output is correct
7 Correct 3 ms 6004 KB Output is correct
8 Correct 6 ms 6004 KB Output is correct
9 Correct 329 ms 6612 KB Output is correct
10 Correct 49 ms 6548 KB Output is correct
11 Correct 59 ms 8552 KB Output is correct
12 Correct 46 ms 8512 KB Output is correct
13 Correct 4016 ms 14868 KB Output is correct
14 Correct 3343 ms 14876 KB Output is correct
15 Correct 93 ms 10036 KB Output is correct
16 Correct 103 ms 9700 KB Output is correct
17 Correct 796 ms 31860 KB Output is correct
18 Correct 823 ms 30820 KB Output is correct
19 Correct 1546 ms 35000 KB Output is correct
20 Correct 719 ms 33064 KB Output is correct
21 Correct 1563 ms 35000 KB Output is correct
22 Correct 1573 ms 33140 KB Output is correct
23 Correct 1899 ms 36420 KB Output is correct
24 Correct 1886 ms 34620 KB Output is correct
25 Correct 2119 ms 36420 KB Output is correct
26 Correct 2116 ms 34620 KB Output is correct
27 Correct 133 ms 10532 KB Output is correct
28 Correct 139 ms 10244 KB Output is correct
29 Correct 1956 ms 32976 KB Output is correct
30 Correct 1623 ms 31788 KB Output is correct
31 Correct 2269 ms 36604 KB Output is correct
32 Correct 1769 ms 34020 KB Output is correct
33 Correct 2069 ms 35048 KB Output is correct
34 Correct 3079 ms 36932 KB Output is correct
35 Correct 2699 ms 36684 KB Output is correct
36 Correct 3053 ms 36816 KB Output is correct
37 Correct 3706 ms 40020 KB Output is correct
38 Correct 3216 ms 36816 KB Output is correct
39 Correct 169 ms 11056 KB Output is correct
40 Correct 156 ms 11084 KB Output is correct
41 Correct 2703 ms 34860 KB Output is correct
42 Correct 2509 ms 34892 KB Output is correct
43 Correct 4089 ms 37236 KB Output is correct
44 Correct 4029 ms 37132 KB Output is correct
45 Correct 4306 ms 37196 KB Output is correct
46 Correct 4053 ms 37196 KB Output is correct
47 Correct 4323 ms 40284 KB Output is correct
48 Correct 4306 ms 40284 KB Output is correct
49 Correct 4493 ms 40284 KB Output is correct
50 Correct 4339 ms 40284 KB Output is correct
51 Execution timed out 5000 ms 40284 KB Execution timed out
52 Halted 0 ms 0 KB -