[CFgym101061C]Ramzi(贪心,双条件最短路)

时间:2023-03-09 09:23:01
[CFgym101061C]Ramzi(贪心,双条件最短路)

题目链接:http://codeforces.com/gym/101061/problem/C

题意:一张图,图上的边有两种,一种是车道,一种是人行道。一个人要从A点到B点,可以坐车也可以走人行道。这个人希望在走最少的路的情况下尽可能早地到达B点(保证走路最少的清空下坐车时间最少),问要走多少路,一共花费多久。

pair<int, int>保存这个人需要走路的时间和共计的时间,读入更新图的时候需要判断仔细。利用pair自身比较运算符优先判断first元素可以直接跑floyd。

 /*
━━━━━┒ギリギリ♂ eye!
┓┏┓┏┓┃キリキリ♂ mind!
┛┗┛┗┛┃\○/
┓┏┓┏┓┃ /
┛┗┛┗┛┃ノ)
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┃┃┃┃┃┃
┻┻┻┻┻┻
*/
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
//#include <unordered_map>
using namespace std;
#define fr first
#define sc second
#define cl clear
#define BUG puts("here!!!")
#define W(a) while(a--)
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%I64d", &a)
#define Rs(a) scanf("%s", a)
#define Cin(a) cin >> a
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(int i = 0; i < (len); i++)
#define For(i, a, len) for(int i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Clr(a, x) memset((a), (x), sizeof(a))
#define Full(a) memset((a), 0x7f7f7f, sizeof(a))
#define lrt rt << 1
#define rrt rt << 1 | 1
#define pi 3.14159265359
#define RT return
#define lowbit(x) x & (-x)
#define onenum(x) __builtin_popcount(x)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<LL, LL> pll;
typedef map<string, int> msi;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb; pii operator+(pii A, pii B) {
return pii(A.first + B.first, A.second + B.second);
}
const int maxn = ;
int n, m;
pii dp[maxn][maxn]; int main() {
// FRead();
int T;
int x, y, c, k;
Rint(T);
W(T) {
Rint(n); Rint(m);
Rep(i, n+) {
Rep(j, n+) dp[i][j] = pii(, );
dp[i][i] = pii(, );
}
Rep(i, m) {
Rint(x); Rint(y); Rint(c); Rint(k);
if(k == ) {
if(dp[x][y].first > c) {
dp[x][y].first = min(dp[x][y].first, c);
dp[y][x].first = min(dp[y][x].first, c);
dp[x][y].second = min(dp[x][y].second, c);
dp[y][x].second = min(dp[y][x].second, c);
}
}
else {
if(dp[x][y].first != ) {
dp[x][y].first = dp[y][x].first = ;
dp[x][y].second = dp[y][x].second = c;
}
else {
dp[x][y].second = min(dp[x][y].second, c);
dp[y][x].second = min(dp[y][x].second, c);
}
}
}
For(k, , n+) For(i, , n+) For(j, , n+)
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
Rint(x); Rint(y);
if(dp[x][y].second >= ) puts("-1");
else printf("%d %d\n", dp[x][y].first, dp[x][y].second);
}
RT ;
}