답안 #28682

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28682 2017-07-16T08:41:37 Z Shocking Hot(#1200, khsoo01) Alternative Mart (FXCUP2_mart) C++14
1 / 1
773 ms 20080 KB
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef pair<int,int> pii;
const int inf = 1e9;

int n, m, k, q, c[50005], vis[50005], ts;
pii d[50005][12];

vector<pii> adj[50005];
priority_queue<pair<pii,int> > pq;

bool upd (int I, pii V) {
	for(int i=0;i<11;i++) {
		if(d[I][i] < V) {
			pii T = d[I][i];
			d[I][i] = V;
			for(int j=i+1;j<11;j++) {
				if(T.Y == V.Y) return true;
				swap(d[I][j], T);
			}
			return true;
		}
		if(d[I][i].Y == V.Y) return false;
	}
	return false;
}

int main()
{
	scanf("%d%d%d%d",&n,&m,&k,&q);
	for(int i=1;i<=n;i++) {
		for(int j=0;j<11;j++) d[i][j] = pii(-inf, 1);
	}
	for(int i=1;i<=k;i++) {
		int T;
		scanf("%d",&T);
		upd(T, pii(0, -T));
		pq.push({pii(0, -T), T});
	}
	for(int i=1;i<=m;i++) {
		int A, B, C;
		scanf("%d%d%d",&A,&B,&C);
		adj[A].push_back({B, C});
		adj[B].push_back({A, C});
	}
	while(!pq.empty()) {
		pii V; int I; tie(V, I) = pq.top(); pq.pop();
		if(c[I] == 11 || d[I][c[I]] != V) continue;
		c[I]++;
		for(auto &T : adj[I]) {
			int A, B; tie(A, B) = T;
			pii X = pii(V.X-B, V.Y);
			if(upd(A, X)) pq.push({X, A});
		}
	}
	while(q--) {
		int A, M; ts++;
		scanf("%d%d",&A,&M);
		for(int i=0;i<M;i++) {
			int T;
			scanf("%d",&T);
			vis[T] = ts;
		}
		for(int i=0;i<11;i++) {
			if(vis[-d[A][i].Y] == ts) continue;
			printf("%d %d\n",-d[A][i].Y,-d[A][i].X);
			break;
		}
	}
}

Compilation message

mart.cpp: In function 'int main()':
mart.cpp:32: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:38:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&T);
                 ^
mart.cpp:44: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);
                           ^
mart.cpp:60:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&A,&M);
                      ^
mart.cpp:63:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&T);
                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 8272 KB Output is correct
2 Correct 0 ms 8272 KB Output is correct
3 Correct 0 ms 8272 KB Output is correct
4 Correct 0 ms 8272 KB Output is correct
5 Correct 0 ms 8272 KB Output is correct
6 Correct 0 ms 8272 KB Output is correct
7 Correct 0 ms 8416 KB Output is correct
8 Correct 0 ms 8272 KB Output is correct
9 Correct 13 ms 9028 KB Output is correct
10 Correct 9 ms 9024 KB Output is correct
11 Correct 26 ms 8724 KB Output is correct
12 Correct 16 ms 8404 KB Output is correct
13 Correct 153 ms 15188 KB Output is correct
14 Correct 146 ms 15204 KB Output is correct
15 Correct 96 ms 10408 KB Output is correct
16 Correct 93 ms 9856 KB Output is correct
17 Correct 413 ms 11376 KB Output is correct
18 Correct 309 ms 9856 KB Output is correct
19 Correct 463 ms 12532 KB Output is correct
20 Correct 376 ms 9856 KB Output is correct
21 Correct 459 ms 12576 KB Output is correct
22 Correct 419 ms 10056 KB Output is correct
23 Correct 563 ms 14812 KB Output is correct
24 Correct 469 ms 12112 KB Output is correct
25 Correct 493 ms 14812 KB Output is correct
26 Correct 503 ms 12112 KB Output is correct
27 Correct 113 ms 10848 KB Output is correct
28 Correct 99 ms 10552 KB Output is correct
29 Correct 569 ms 12856 KB Output is correct
30 Correct 489 ms 11340 KB Output is correct
31 Correct 579 ms 15000 KB Output is correct
32 Correct 489 ms 11228 KB Output is correct
33 Correct 519 ms 12656 KB Output is correct
34 Correct 583 ms 15344 KB Output is correct
35 Correct 569 ms 14944 KB Output is correct
36 Correct 606 ms 15076 KB Output is correct
37 Correct 579 ms 19816 KB Output is correct
38 Correct 566 ms 15076 KB Output is correct
39 Correct 113 ms 11536 KB Output is correct
40 Correct 99 ms 11536 KB Output is correct
41 Correct 476 ms 15568 KB Output is correct
42 Correct 636 ms 15572 KB Output is correct
43 Correct 736 ms 15572 KB Output is correct
44 Correct 706 ms 15580 KB Output is correct
45 Correct 709 ms 15616 KB Output is correct
46 Correct 626 ms 15632 KB Output is correct
47 Correct 689 ms 20080 KB Output is correct
48 Correct 773 ms 20080 KB Output is correct
49 Correct 636 ms 20080 KB Output is correct
50 Correct 713 ms 20080 KB Output is correct
51 Correct 593 ms 20080 KB Output is correct
52 Correct 629 ms 20080 KB Output is correct
53 Correct 249 ms 9856 KB Output is correct
54 Correct 583 ms 15260 KB Output is correct
55 Correct 716 ms 15240 KB Output is correct
56 Correct 739 ms 15612 KB Output is correct
57 Correct 156 ms 12520 KB Output is correct