Submission #732327

#TimeUsernameProblemLanguageResultExecution timeMemory
732327yeysoTwo Currencies (JOI23_currencies)C++14
10 / 100
5077 ms56264 KiB
#include <bits/stdc++.h> using namespace std; //#define long long long long; vector<vector<long long>> adj; vector<vector<long long>> ddj; vector<vector<long long>> rdj; vector<vector<long long>> roads; vector<vector<long long>> che; long long solve(long long s, long long t, long long x, long long y, long long n){ // road, node, parent queue<vector<long long>> q; q.push({-1, s, s}); vector<long long> v(n, 0); vector<long long> parents(n, 0); vector<long long> ru(n, 0); parents[s] = -1; long long node; long long road; long long parent; while(!q.empty()){ node = q.front()[1]; road = q.front()[0]; parent = q.front()[2]; q.pop(); if(!v[node]){ parents[node] = parent; ru[node] = road; v[node] = 1; for(long long i = 0; i < adj[node].size(); i ++){ q.push({rdj[node][i], adj[node][i], node}); } } } vector<long long> coins; node = t; while(parents[node] != node){ if(ru[node] >= 0){ for(long long i = 0; i < che[ru[node]].size(); i ++){ coins.push_back(che[ru[node]][i]); } } node = parents[node]; } sort(coins.begin(), coins.end()); for(long long i = 0; i < coins.size(); i ++){ if(y - coins[i] >= 0){ y -= coins[i]; } else { x -= 1; } } if(x >= 0){ return x; } else { return -1; } } int main(){ long long n, m, queries; cin >> n >> m >> queries; vector<vector<long long>> adj0(n, vector<long long>()); vector<vector<long long>> ddj0(n, vector<long long>()); vector<vector<long long>> rdj0(n, vector<long long>()); vector<vector<long long>> roads; long long a, b, p, c; for(long long i = 0; i < n - 1; i ++){ cin >> a >> b; a -= 1; b -= 1; roads.push_back({a, b}); } vector<vector<long long>> checkpoints(n-1, vector<long long>()); for(long long i = 0; i < m; i ++){ cin >> p >> c; p -= 1; checkpoints[p].push_back(c); } for(long long i = 0; i < roads.size(); i ++){ adj0[roads[i][0]].push_back(roads[i][1]); adj0[roads[i][1]].push_back(roads[i][0]); ddj0[roads[i][0]].push_back(roads[i][2]); ddj0[roads[i][1]].push_back(roads[i][2]); rdj0[roads[i][0]].push_back(i); rdj0[roads[i][1]].push_back(i); } adj = adj0; ddj = ddj0; rdj = rdj0; che = checkpoints; long long s, t, x, y; vector<long long> res; for(long long i = 0; i < queries; i ++){ cin >> s >> t >> x >> y; s -= 1; t -= 1; res.push_back(solve(s, t, x, y, n)); } for(long long i = 0; i < res.size(); i ++){ cout << res[i] << "\n"; } } /* g++ -std=gnu++17 -O2 -pipe -o 7 7.cpp 5 4 3 1 2 1 3 2 4 2 5 2 9 2 4 3 5 4 7 3 4 2 11 5 3 4 5 2 3 1 1 */

Compilation message (stderr)

currencies.cpp: In function 'long long int solve(long long int, long long int, long long int, long long int, long long int)':
currencies.cpp:25:36: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |             for(long long i = 0; i < adj[node].size(); i ++){
      |                                  ~~^~~~~~~~~~~~~~~~~~
currencies.cpp:34:36: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |             for(long long i = 0; i < che[ru[node]].size(); i ++){
      |                                  ~~^~~~~~~~~~~~~~~~~~~~~~
currencies.cpp:41:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(long long i = 0; i < coins.size(); i ++){
      |                          ~~^~~~~~~~~~~~~~
currencies.cpp: In function 'int main()':
currencies.cpp:71:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for(long long i = 0; i < roads.size(); i ++){
      |                          ~~^~~~~~~~~~~~~~
currencies.cpp:85:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |     for(long long i = 0; i < res.size(); i ++){
      |                          ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...