拿下
2026-09-19 14:11:51
发布于:广东
执行用时:18ms
内存消耗:3.75MB
击败了100.00%的用户
击败了100.00%的用户
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#include <unistd.h>
#include <queue>
using namespace std;
static char inBuf[1 << 16];
static int inLen = 0, inPos = 0;
inline int readChar() {
if (inPos == inLen) {
inLen = read(0, inBuf, sizeof(inBuf));
inPos = 0;
if (inLen <= 0) return -1;
}
return inBuf[inPos++];
}
inline int readInt() {
int c = readChar();
while (c <= ' ') { if (c == -1) return 0; c = readChar(); }
int x = 0;
while (c > ' ') { x = (x << 3) + (x << 1) + (c - '0'); c = readChar(); }
return x;
}
static char outBuf[1 << 16];
static int outLen = 0;
inline void flushOut() {
if (outLen > 0) { write(1, outBuf, outLen); outLen = 0; }
}
inline void outStr(const char* s) {
while (*s) {
if (outLen == (int)sizeof(outBuf)) flushOut();
outBuf[outLen++] = *s++;
}
}
const int MAXN = 505;
const int INF = 1000000000;
struct Edge {
int to, l, t;
int next;
} edges[1005];
int head[MAXN];
int edgeCnt = 0;
inline void addEdge(int u, int v, int l, int t) {
edges[++edgeCnt].to = v;
edges[edgeCnt].l = l;
edges[edgeCnt].t = t;
edges[edgeCnt].next = head[u];
head[u] = edgeCnt;
}
static int late[MAXN][MAXN];
int main() {
int n = readInt();
int m = readInt();
int q = readInt();
for (int i = 1; i <= n; i++) head[i] = 0;
for (int i = 0; i < m; i++) {
int u = readInt();
int v = readInt();
int l = readInt();
int t = readInt();
addEdge(v, u, l, t); // 反向建图
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
late[i][j] = -1;
for (int y = 1; y <= n; y++) {
priority_queue<pair<int,int>> pq;
late[y][y] = INF;
pq.push({INF, y});
while (!pq.empty()) {
auto top = pq.top(); pq.pop();
int d = top.first;
int v = top.second;
if (d < late[y][v]) continue;
for (int e = head[v]; e; e = edges[e].next) {
int u = edges[e].to;
int l = edges[e].l;
int t = edges[e].t;
int val = l < late[y][v] - t ? l : late[y][v] - t;
if (val > late[y][u]) {
late[y][u] = val;
pq.push({val, u});
}
}
}
}
while (q--) {
int x = readInt();
int y = readInt();
int s = readInt();
if (late[y][x] >= s) outStr("Yes\n");
else outStr("No\n");
}
flushOut();
return 0;
}
全部评论 1
求点赞
昨天 来自 广东
0






有帮助,赞一个