답안 #28670

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28670 2017-07-16T08:34:56 Z tlwpdus 팬클럽 회장(#1123, kdh9949) Alternative Mart (FXCUP2_mart) C++14
0 / 1
3 ms 5740 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){ fl = 0; break; }
			}
			if(!fl) continue;
			pii cq = pii(nd, c.s);
			md[nx].insert(cq);
			while(md[nx].size() > 11) md[nx].erase(*md[nx].rbegin());
			if(md[nx].find(cq) != md[nx].end()) 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:47: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:49: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 Incorrect 3 ms 5740 KB Output isn't correct
6 Halted 0 ms 0 KB -