Submission #880558

# Submission time Handle Problem Language Result Execution time Memory
880558 2023-11-29T16:17:19 Z tsumondai Autobus (COCI22_autobus) C++14
0 / 70
7 ms 23900 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME  (1.0 * clock() / CLOCKS_PER_SEC)

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 1e6 + 5;
 
const int oo = 1e9, mod = 1e9 + 7;
 
int n, m, k, q;
string s;
vector<ii> adj[N];

// precalc

void process() {
	cin >> n >> m;
	vector<vector<int>> c(n+1, vector<int>(n+1, oo));
	foru(i,1,n) c[i][i]=0;
	foru(i,1,m) {
		int u, v, t; cin >> u >> v >> t;
		u--, v--;
		c[u][v]=min(c[u][v], t);
	}

	cin >> k >> q;

	k=min(k,n);


	auto sol=c;

	foru(cnt, 1, k-1) {
		auto newsol=sol;
		for (int x = 0; x < n; x++)
            for (int y = 0; y < n; y++)
                for (int z = 0; z < n; z++)
					newsol[x][y] = min(newsol[x][y], sol[x][z] + c[z][y]);
		sol=newsol;
	}

	while (q--) {
		int s, t;
		cin >> s >> t;
		s--, t--;
		if (sol[s][t]>=oo) cout << -1 << '\n'; else cout << sol[s][t] << '\n';
	}

    return;
}

signed main() {
    cin.tie(0)->sync_with_stdio(false);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
    process();
    cerr << "Time elapsed: " << __TIME << " s.\n";
    return 0;
}

/*
Xét các trường hợp đặc biệt
Kiểm tra lại input/output
Cố gắng trâu
Lật ngược bài toán
Keep calm and get VOI 
Flow:

*/

Compilation message

Main.cpp: In function 'void process()':
Main.cpp:47:13: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   47 |             for (int y = 0; y < n; y++)
      |             ^~~
Main.cpp:50:3: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   50 |   sol=newsol;
      |   ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 23896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 23900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 23896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 23896 KB Output isn't correct
2 Halted 0 ms 0 KB -