답안 #205774

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
205774 2020-02-29T20:40:13 Z ly20 Toll (BOI17_toll) C++17
0 / 100
97 ms 28152 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 512345;
const long long INF = 1123456789012;
long long v[MAXN];
vector <int> grafo[MAXN];
vector <long long> peso[MAXN];
long long dist[MAXN];
int grau[MAXN];
int main() {
	int k, n, m, o;
	scanf("%d %d %d %d", &k, &n, &m, &o);
	for(int i = 0; i < m; i++) {
		int a, b;
		long long p;
		scanf("%d %d", &a, &b);
		grau[b]++;
		scanf("%lld", &p);
		grafo[a].push_back(b);
		peso[a].push_back(p);
	}
	for(int i = 0; i < n; i++) dist[i] = INF;
	dist[0] = 0LL;
	queue <int> fila;
	fila.push(0);
	while(!fila.empty()) {
		int cur = fila.front();
		fila.pop();
		for(int i = 0; i < grafo[cur].size(); i++) {
			int viz = grafo[cur][i];
			long long p = peso[cur][i];
			dist[viz] = min(dist[viz], dist[cur] + p);
			grau[viz]--;
			if(grau[viz] == 0) fila.push(viz);
		}
	}
	for(int i = 0; i < o; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		if(dist[b] >= INF) printf("-1\n");
		else printf("%lld\n", dist[b]);
	}
	return 0;
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:29:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < grafo[cur].size(); i++) {
                  ~~^~~~~~~~~~~~~~~~~~~
toll.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d %d", &k, &n, &m, &o);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~~
toll.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &p);
   ~~~~~^~~~~~~~~~~~
toll.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 66 ms 28152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 97 ms 28152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 24440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 24440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 66 ms 28152 KB Output isn't correct
2 Halted 0 ms 0 KB -