답안 #205776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
205776 2020-02-29T20:50:20 Z ly20 Toll (BOI17_toll) C++17
8 / 100
3000 ms 32216 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], grau1[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 < o; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		for(int i = 0; i < n; i++) dist[i] = INF;
		dist[a] = 0LL;
		queue <int> fila;
		for(int i = 0; i < n; i++) if(grau[i] == 0) fila.push(i);
		for(int i = 0; i < n; i++) grau1[i] = grau[i];
		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);
				grau1[viz]--;
				if(grau1[viz] == 0) fila.push(viz);
			}
		}
		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:33:21: 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:24: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 Execution timed out 3066 ms 28536 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3089 ms 28280 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 24440 KB Output is correct
2 Correct 20 ms 24440 KB Output is correct
3 Correct 20 ms 24440 KB Output is correct
4 Correct 21 ms 24440 KB Output is correct
5 Correct 21 ms 24440 KB Output is correct
6 Correct 23 ms 24568 KB Output is correct
7 Correct 24 ms 24568 KB Output is correct
8 Correct 27 ms 24568 KB Output is correct
9 Correct 26 ms 24568 KB Output is correct
10 Correct 341 ms 29296 KB Output is correct
11 Correct 296 ms 29944 KB Output is correct
12 Correct 430 ms 31736 KB Output is correct
13 Correct 452 ms 32216 KB Output is correct
14 Correct 436 ms 30584 KB Output is correct
15 Correct 241 ms 28280 KB Output is correct
16 Correct 227 ms 28280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 24440 KB Output is correct
2 Correct 20 ms 24440 KB Output is correct
3 Correct 20 ms 24440 KB Output is correct
4 Correct 21 ms 24440 KB Output is correct
5 Correct 21 ms 24440 KB Output is correct
6 Correct 23 ms 24568 KB Output is correct
7 Correct 24 ms 24568 KB Output is correct
8 Correct 27 ms 24568 KB Output is correct
9 Correct 26 ms 24568 KB Output is correct
10 Correct 341 ms 29296 KB Output is correct
11 Correct 296 ms 29944 KB Output is correct
12 Correct 430 ms 31736 KB Output is correct
13 Correct 452 ms 32216 KB Output is correct
14 Correct 436 ms 30584 KB Output is correct
15 Correct 241 ms 28280 KB Output is correct
16 Correct 227 ms 28280 KB Output is correct
17 Execution timed out 3085 ms 30072 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3066 ms 28536 KB Time limit exceeded
2 Halted 0 ms 0 KB -