Submission #205776

#TimeUsernameProblemLanguageResultExecution timeMemory
205776ly20Toll (BOI17_toll)C++17
8 / 100
3089 ms32216 KiB
#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 (stderr)

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);
   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...