0% found this document useful (0 votes)
9 views2 pages

Floyd

Uploaded by

Thang Giang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Floyd

Uploaded by

Thang Giang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <bits/stdc++.

h>
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define __builtin_popcount __builtin_popcountll
#define __builtin_ctz __builtin_ctzll
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define vi vector<int>
#define mii map<int, int>
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#define mirai ""
template<class X, class Y>
bool minimize(X& x, const Y& y) {
X eps = 1e-9;
if (x > y + eps) {
x = y;
return true;
}
else return false;
}
template<class X, class Y>
bool maximize(X& x, const Y& y) {
X eps = 1e-9;
if (x + eps < y) {
x = y;
return true;
}
else return false;
}
template<class T>
T Abs(const T& x) {
return (x < 0 ? -x : x);
}
const int INF = 1e9 + 7;
const ll oo = 1e18 + 7;
const int MAX = 1000005;
using namespace std;
int next1[1001][1001], a[1001][1001];
void progress() {
int lmao, i, j;
cin >> lmao >> i >> j;
if(lmao == 0){
cout << a[i][j] << endl;
}
else{
vi b;
for(int tmp = i; tmp != j; tmp = next1[tmp][j]){
b.pb(tmp);
}
b.pb(j);
cout << b.size() << " ";
for(int i = 0; i < b.size(); i++)
cout << b[i] << " ";
cout << endl;
}
}
signed main()
{
if (fopen(mirai".inp", "r")) {
freopen(mirai".inp", "r", stdin);
freopen(mirai".out", "w", stdout);
}
int Test, n, m;
cin >> n >> m >> Test;
memset(a, 0x3f, sizeof(a));
for(int i = 1; i <= m; i++){
int x, y, w;
cin >> x >> y >> w;
a[x][y] = w;
a[y][x] = w;
next1[x][y] = y;
next1[y][x] = x;
}
for(int k = 1; k <= n; k++){
a[k][k] = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(a[i][j] > a[i][k] + a[k][j]){
a[i][j] = a[i][k] + a[k][j];
next1[i][j] = next1[i][k];
}
}
}
}
while (Test--) {
progress();
}
return 0;
}

You might also like