제출 #522154

#제출 시각아이디문제언어결과실행 시간메모리
522154YuDabin약속장소 정하기 (GCJ12KOR_appointment)C++14
0 / 35
3092 ms22316 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
const int INF = 1e16;

int n, p, m;
vector<pair<int, int>> man;
vector<vector<pair<int, int>>> graph;
vector<int> ans;

void dijkstra(int i)
{
	vector<int> dist(n+1, INF);
	priority_queue<pair<int, int>> pq; pq.push({0, man[i].first});
	
	while(!pq.empty())
	{
		int here = pq.top().second, cost = -pq.top().first; pq.pop();
		dist[here] = cost;
		
		for(auto it : graph[here])
		{
			int there = it.first, ncost = cost + it.second * man[i].second;
			if(dist[there] != INF) continue;
			pq.push({-ncost, there});
		}
	}
	
	for(int j = 1; j <= n; j++) ans[j] = max(ans[j], dist[j]);
}

int32_t main()
{
	int T; scanf("%lld", &T);
	for(int t = 1; t <= T; t++)
	{
		scanf("%lld%lld%lld", &n, &p, &m);
		
		man.clear(); graph.clear();
		man.resize(p+1); graph.resize(n+1);
		for(int i = 1; i <= p; i++) scanf("%lld%lld", &man[i].first, &man[i].second);
		for(int i = 1; i <= m; i++)
		{
			int d, l; scanf("%lld%lld", &d, &l); int prv, here;
			scanf("%lld", &prv);
			for(int j = 2; j <= l; j++)
			{
				scanf("%lld", &here);
				graph[here].push_back({prv, d});
				graph[prv].push_back({here, d});
				prv = here;
			}
		}
		ans.resize(n+1, -1);
		for(int i = 1; i <= p; i++) dijkstra(i);
		
		int res = ans[1];
		for(int i = 2; i <= n; i++) res = min(res, ans[i]);
		printf("Case #%lld: %lld\n", t, (res == INF ? -1 : res));
	}
}

컴파일 시 표준 에러 (stderr) 메시지

C.cpp: In function 'int32_t main()':
C.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |  int T; scanf("%lld", &T);
      |         ~~~~~^~~~~~~~~~~~
C.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%lld%lld%lld", &n, &p, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
C.cpp:42:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |   for(int i = 1; i <= p; i++) scanf("%lld%lld", &man[i].first, &man[i].second);
      |                               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C.cpp:45:19: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |    int d, l; scanf("%lld%lld", &d, &l); int prv, here;
      |              ~~~~~^~~~~~~~~~~~~~~~~~~~
C.cpp:46:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |    scanf("%lld", &prv);
      |    ~~~~~^~~~~~~~~~~~~~
C.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     scanf("%lld", &here);
      |     ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...