QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#340629 | #4437. Link with Running | Terac# | TL | 0ms | 0kb | C++14 | 2.7kb | 2024-02-29 10:51:01 | 2024-02-29 10:51:01 |
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
namespace IO {
#if ONLINE_JUDGE
#define getc() (IS == IT && (IT = (IS = ibuf) + fread(ibuf, 1, IL, stdin), IS == IT) ? EOF : *IS++)
#else
#define getc() getchar()
#endif
const int IL = 1 << 21, OL = 1 << 21;
int olen = 0;
char ibuf[IL], *IS = ibuf, *IT = ibuf, obuf[OL];
inline int read() {
register char ch = getc(); register int x = 0, f = 1;
while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getc(); }
while(isdigit(ch)) x = x * 10 + ch - 48, ch = getc();
return x * f;
}
inline double readdb() {
register char ch = getc(); register double x = 0, f = 1;
while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getc(); }
while(isdigit(ch)) x = x * 10 + ch - 48, ch = getc();
if(ch == '.') {
register double b = 0.1;
ch = getc();
while(isdigit(ch)) x += (ch - 48) * b, b *= 0.1, ch = getc();
}
return x * f;
}
inline int readstr(char *s) {
register char ch = getc(); register int len = 0;
while(!isalpha(ch)) ch = getc();
while(isalpha(ch)) s[++len] = ch, ch = getc();
return len;
}
inline void flush() { fwrite(obuf, 1, olen, stdout); olen = 0; }
inline void putc(register char ch) { obuf[olen++] = ch; }
template<class T>
inline void write(register T x) {
if(x < 0) obuf[olen++] = '-', x = -x;
if(x > 9) write(x / 10);
obuf[olen++] = x % 10 + 48;
}
} using namespace IO;
const int N = 3e5 + 10;
int n, m;
struct edge {
int to, w, c, nxt;
} e[N];
int head[N], ecnt;
void addedge(int u, int v, int w, int c) {
e[++ecnt] = {v, w, c, head[u]};
head[u] = ecnt;
}
int dis[N], dis2[N];
struct node {
int dis, dis2, u;
bool operator < (const node &y) const {
return dis == y.dis ? dis2 < y.dis2 : dis > y.dis;
}
};
bool vis[N];
void dij() {
memset(vis, 0, sizeof(vis));
memset(dis, 0x3f, sizeof(dis));
// cout << dis[5] << endl;
memset(dis2, 0, sizeof(dis2));
priority_queue<node> q;
q.push((node){0, 0, 1});
dis[1] = 0;
while(!q.empty()) {
int u = q.top().u;
q.pop();
vis[u] = 0;
for(int i = head[u], v; i; i = e[i].nxt) {
v = e[i].to;
if(dis[v] > dis[u] + e[i].w || (dis[v] == dis[u] + e[i].w && dis2[v] < dis2[u] + e[i].c)) {
dis[v] = dis[u] + e[i].w;
dis2[v] = dis2[u] + e[i].c;
if(!vis[v]) vis[v] = 1, q.push({dis[v], dis2[v], v});
}
}
}
}
void MAIN() {
n = read(), m = read();
ecnt = 0;
memset(head, 0, sizeof(head));
for(int i = 1, u, v, e, p; i <= m; i++)
u = read(), v = read(), e = read(), p = read(), addedge(u, v, e, p);
dij();
printf("%lld %lld\n", dis[n], dis2[n]);
}
signed main() {
int T = read();
while(T--) MAIN();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
12 100000 200000 1 2 838279516 902819511 1 3 293478832 513256010 2 4 682688353 204481674 2 5 360092507 651108247 5 6 519851939 323803002 6 7 675439277 205804465 7 8 419167205 386168059 6 9 140767493 382483305 9 10 558115401 613738466 9 11 902235661 744659643 9 12 851394758 1720015 12 13 635355827 46...