Submission #714728

#TimeUsernameProblemLanguageResultExecution timeMemory
714728IliyaToll (BOI17_toll)C++17
7 / 100
3067 ms6144 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e4 + 10;
const int Inf = 0x3f3f3f3f;
vector<pair<int, int>> Adj[N], Order;
int n, m, k, o, C[N], D[N], mark[N];
void DFS(int v, int comp) 
{
	mark[v] = true;
	C[v] = comp;
	for (auto [u, w] : Adj[v])
		D[u] = D[v] + w, DFS(u, comp);
}
signed main() 
{	
	scanf("%d%d%d%d", &k, &n, &m, &o);
	for (int i = 0; i < m; i++) 
	{
		int a, b, t;
		scanf("%d%d%d", &a, &b, &t);
		Adj[a].emplace_back(b, t);
	}
	for (int i = 0; i < o; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		Order.emplace_back(a, b);
	}
	for (int i = 0; i < n; i++) 
		if (!mark[i]) DFS(i, i);
	for (auto [u, v] : Order) 
	{
		if (u < v) swap(u, v);
		if (C[u] == C[v]) 
			printf("%d\n", D[u] - D[v]);
		else 
			printf("%d\n", -1);
	}
	return 0;
}

Compilation message (stderr)

toll.cpp: In function 'int main()':
toll.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |  scanf("%d%d%d%d", &k, &n, &m, &o);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   scanf("%d%d%d", &a, &b, &t);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
toll.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   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...