QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#842630 | #9960. Baggage | ucup-team5243# | WA | 2ms | 3980kb | C++23 | 11.5kb | 2025-01-04 13:47:19 | 2025-01-04 13:47:20 |
Judging History
answer
//line 1 "answer.cpp"
#if !__INCLUDE_LEVEL__
#include __FILE__
int main() {
ll n,m; input(n, m);
vector<tuple<ll,ll,ll,ll>> edges;
rep(i, m) {
ll u,v,c,di; input(u,v,c,di);
--u; --v;
edges.emplace_back(u,v,c,di);
}
// すべての辺のグラフ
vector g(n, vector<ll>(n, INFL));
// コスト1以上の辺のグラフ
vector g1(n, vector<ll>(n, INFL));
rep(i, n) g[i][i] = 0;
rep(i, n) g1[i][i] = 0;
rep(i, m) {
auto [u,v,c,di] = edges[i];
chmin(g[u][v], c);
if (di >= 1) chmin(g1[u][v], c);
}
rep(k, n) rep(i, n) rep(j, n) {
chmin(g[i][j], g[i][k] + g[k][j]);
chmin(g1[i][j], g1[i][k] + g1[k][j]);
}
vector gn(n, vector<ll>(n, INFL));
rep(i, n) gn[i][i] = 0;
rep(i, m) {
auto [u,v,c,di] = edges[i];
if (di == 2) chmin(gn[u][v], c);
}
rep(u, n) rep(v, n) {
chmin(gn[u][v], g1[u][v] + g[v][u] + g1[u][v]);
}
rep(k, n) rep(i, n) rep(j, n) {
chmin(gn[i][j], gn[i][k] + gn[k][j]);
}
rep(i, n) {
rep(j, n) if (gn[i][j] == INFL) gn[i][j] = -1;
print(gn[i]);
}
}
#else
//line 2 "/home/seekworser/.cpp_lib/competitive_library/competitive/std/std.hpp"
#include <bits/stdc++.h>
#ifndef LOCAL_TEST
#pragma GCC target ("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif // LOCAL_TEST
using namespace std;
using std::cout;
// shorten typenames
using ll = long long;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vl = vector<ll>; using vvl = vector<vl>; using vvvl = vector<vvl>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vc = vector<char>; using vvc = vector<vc>; using vvvc = vector<vvc>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
using vs = vector<string>; using vvs = vector<vector<string>>; using vvvs = vector<vector<vector<string>>>;
template<typename T> vector<vector<T>> vv(int h, int w, T val = T()) { return vector(h, vector<T>(w, val)); }
template<typename T> vector<vector<vector<T>>> vvv(int h1, int h2, int h3, T val = T()) { return vector(h1, vector(h2, vector<T>(h3, val))); }
template<typename T> vector<vector<vector<vector<T>>>> vvvv(int h1, int h2, int h3, int h4, T val = T()) { return vector(h1, vector(h2, vector(h3, vector<T>(h4, val)))); }
template <class T> using priority_queue_min = priority_queue<T, vector<T>, greater<T>>;
// define CONSTANTS
constexpr double PI = 3.14159265358979323;
constexpr int INF = 100100111; constexpr ll INFL = 3300300300300300491LL;
float EPS = 1e-8; double EPSL = 1e-10;
template<typename T> bool eq(const T x, const T y) { return x == y; }
template<> bool eq<double>(const double x, const double y) { return (abs(x - y) < EPSL * x || abs(x - y) < EPSL); }
template<> bool eq<float>(const float x, const float y) { return abs(x - y) < EPS * x; }
template<typename T> bool neq(const T x, const T y) { return !(eq<T>(x, y)); }
template<typename T> bool ge(const T x, const T y) { return (eq<T>(x, y) || (x > y)); }
template<typename T> bool le(const T x, const T y) { return (eq<T>(x, y) || (x < y)); }
template<typename T> bool gt(const T x, const T y) { return !(le<T>(x, y)); }
template<typename T> bool lt(const T x, const T y) { return !(ge<T>(x, y)); }
constexpr int MODINT998244353 = 998244353;
constexpr int MODINT1000000007 = 1000000007;
// fasten io
struct Nyan { Nyan() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(18); } } nyan;
// define macros
#define all(a) (a).begin(), (a).end()
#define sz(x) ((ll)(x).size())
#define rep1(n) for(ll dummy_iter = 0LL; dummy_iter < n; ++dummy_iter) // 0,1,...,n-1
#define rep2(i, n) for(ll i = 0LL, i##_counter = 0LL; i##_counter < ll(n); ++(i##_counter), (i) = i##_counter) // i=0,1,...,n-1
#define rep3(i, s, t) for(ll i = ll(s), i##_counter = ll(s); i##_counter < ll(t); ++(i##_counter), (i) = (i##_counter)) // i=s,s+1,...,t-1
#define rep4(i, s, t, step) for(ll i##_counter = step > 0 ? ll(s) : -ll(s), i##_end = step > 0 ? ll(t) : -ll(t), i##_step = abs(step), i = ll(s); i##_counter < i##_end; i##_counter += i##_step, i = step > 0 ? i##_counter : -i##_counter) // i=s,s+step,...,<t
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define repe(a, v) for(auto& a : (v)) // iterate over all elements in v
#define smod(n, m) ((((n) % (m)) + (m)) % (m))
#define sdiv(n, m) (((n) - smod(n, m)) / (m))
#define uniq(a) {sort(all(a)); (a).erase(unique(all(a)), (a).end());}
int Yes(bool b=true) { cout << (b ? "Yes\n" : "No\n"); return 0; };
int YES(bool b=true) { cout << (b ? "YES\n" : "NO\n"); return 0; };
int No(bool b=true) {return Yes(!b);};
int NO(bool b=true) {return YES(!b);};
template<typename T, size_t N> T max(array<T, N>& a) { return *max_element(all(a)); };
template<typename T, size_t N> T min(array<T, N>& a) { return *min_element(all(a)); };
template<typename T> T max(vector<T>& a) { return *max_element(all(a)); };
template<typename T> T min(vector<T>& a) { return *min_element(all(a)); };
template<typename T> vector<T> vec_slice(const vector<T>& a, int l, int r) { vector<T> rev; rep(i, l, r) rev.push_back(a[i]); return rev; };
template<typename T> T sum(vector<T>& a, T zero = T(0)) { T rev = zero; rep(i, sz(a)) rev += a[i]; return rev; };
template<typename T> bool in_range(const T& val, const T& s, const T& t) { return s <= val && val < t; };
template <class T> inline vector<T>& operator--(vector<T>& v) { repe(x, v) --x; return v; }
template <class T> inline vector<T>& operator++(vector<T>& v) { repe(x, v) ++x; return v; }
ll powm(ll a, ll n, ll mod=INFL) {
ll res = 1;
while (n > 0) {
if (n & 1) res = (res * a) % mod;
if (n > 1) a = (a * a) % mod;
n >>= 1;
}
return res;
}
ll sqrtll(ll x) {
assert(x >= 0);
ll rev = sqrt(x);
while(rev * rev > x) --rev;
while((rev+1) * (rev+1)<=x) ++rev;
return rev;
}
template <class T> inline bool chmax(T& M, const T& x) { if (M < x) { M = x; return true; } return false; }
template <class T> inline bool chmin(T& m, const T& x) { if (m > x) { m = x; return true; } return false; }
int digit(ll x, int d=10) { int rev=0; while (x > 0) { rev++; x /= d;}; return rev; }
/**
* @brief std.hpp
* @docs docs/std/std.md
*/
//line 3 "/home/seekworser/.cpp_lib/competitive_library/competitive/std/io.hpp"
// overload operators (prototypes)
template <class T, class U> inline istream& operator>>(istream& is, pair<T, U>& p);
template <class T> inline istream& operator>>(istream& is, vector<T>& v);
template <class T, class U> inline ostream& operator<<(ostream& os, const pair<T, U>& p);
template <class T> inline ostream& operator<<(ostream& os, const vector<T>& v);
template <typename T, typename S> ostream &operator<<(ostream &os, const map<T, S> &mp);
template <typename T> ostream &operator<<(ostream &os, const set<T> &st);
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &st);
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T> &st);
template <typename T> ostream &operator<<(ostream &os, queue<T> q);
template <typename T> ostream &operator<<(ostream &os, deque<T> q);
template <typename T> ostream &operator<<(ostream &os, stack<T> st);
template <class T, class Container, class Compare> ostream &operator<<(ostream &os, priority_queue<T, Container, Compare> pq);
// overload operators
template <class T, class U> inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template <class T> inline istream& operator>>(istream& is, vector<T>& v) { repe(x, v) is >> x; return is; }
template <class T, class U> inline ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.first << " " << p.second; return os; }
template <class T> inline ostream& operator<<(ostream& os, const vector<T>& v) { rep(i, sz(v)) { os << v.at(i); if (i != sz(v) - 1) os << " "; } return os; }
template <typename T, typename S> ostream &operator<<(ostream &os, const map<T, S> &mp) { for (auto &[key, val] : mp) { os << key << ":" << val << " "; } return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &st) { auto itr = st.begin(); for (int i = 0; i < (int)st.size(); i++) { os << *itr << (i + 1 != (int)st.size() ? " " : ""); itr++; } return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &st) { auto itr = st.begin(); for (int i = 0; i < (int)st.size(); i++) { os << *itr << (i + 1 != (int)st.size() ? " " : ""); itr++; } return os; }
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T> &st) { ll cnt = 0; for (auto &e : st) { os << e << (++cnt != (int)st.size() ? " " : ""); } return os; }
template <typename T> ostream &operator<<(ostream &os, queue<T> q) { while (q.size()) { os << q.front() << " "; q.pop(); } return os; }
template <typename T> ostream &operator<<(ostream &os, deque<T> q) { while (q.size()) { os << q.front(); q.pop_front(); if (q.size()) os << " "; } return os; }
template <typename T> ostream &operator<<(ostream &os, stack<T> st) { while (st.size()) { os << st.top() << " "; st.pop(); } return os; }
template <class T, class Container, class Compare> ostream &operator<<(ostream &os, priority_queue<T, Container, Compare> pq) { while (pq.size()) { os << pq.top() << " "; pq.pop(); } return os; }
template <typename T> int print_sep_end(string sep, string end, const T& val) { (void)sep; cout << val << end; return 0; };
template <typename T1, typename... T2> int print_sep_end(string sep, string end, const T1 &val, const T2 &...remain) {
cout << val << sep;
print_sep_end(sep, end, remain...);
return 0;
};
template <typename... T> int print(const T &...args) { print_sep_end(" ", "\n", args...); return 0; };
template <typename... T> void flush() { cout << flush; };
template <typename... T> int print_and_flush(const T &...args) { print(args...); flush(); return 0; };
#define debug(...) debug_func(0, #__VA_ARGS__, __VA_ARGS__) // debug print
template <typename T> void input(T &a) { cin >> a; };
template <typename T1, typename... T2> void input(T1&a, T2 &...b) { cin >> a; input(b...); };
#ifdef LOCAL_TEST
template <typename T> void debug_func(int i, const T name) { (void)i; (void)name; cerr << endl; }
template <typename T1, typename T2, typename... T3> void debug_func(int i, const T1 &name, const T2 &a, const T3 &...b) {
int scope = 0;
for ( ; (scope != 0 || name[i] != ',') && name[i] != '\0'; i++ ) {
cerr << name[i];
if (name[i] == '(' || name[i] == '{') scope++;
if (name[i] == ')' || name[i] == '}') scope--;
}
cerr << ":" << a << " ";
debug_func(i + 1, name, b...);
}
template <typename T1, typename T2, typename... T3> void debug_func(int i, const T1 &name, T2 &a, T3 &...b) {
int scope = 0;
for ( ; (scope != 0 || name[i] != ',') && name[i] != '\0'; i++ ) {
cerr << name[i];
if (name[i] == '(' || name[i] == '{') scope++;
if (name[i] == ')' || name[i] == '}') scope--;
}
cerr << ":" << a << " ";
debug_func(i + 1, name, b...);
}
#endif
#ifndef LOCAL_TEST
template <typename... T>
void debug_func(T &...) {}
template <typename... T>
void debug_func(const T &...) {}
#endif
/**
* @brief io.hpp
* @docs docs/std/io.md
*/
//line 46 "answer.cpp"
#endif
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
input:
5 7 1 2 500 2 2 3 100 1 3 5 20 2 5 4 5 1 4 2 1 0 3 4 40 2 5 4 77 1
output:
0 500 726 751 746 -1 0 226 251 246 -1 -1 0 40 20 -1 -1 -1 0 -1 -1 -1 -1 131 0
result:
ok 25 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
30 5000 1 15 15034 0 1 15 15034 0 24 28 14745 2 1 15 15034 0 16 25 13210 0 16 22 26942 0 24 20 5423 1 4 12 636 0 16 12 19327 0 1 15 15034 0 1 15 15034 0 3 28 18940 2 1 15 15034 0 15 9 6468 0 20 3 6233 2 19 4 10829 2 1 15 15034 0 26 6 20998 0 1 15 15034 0 1 15 15034 0 1 15 15034 0 4 14 20515 2 1 15 1...
output:
0 868 1159 2449 3001 1108 1557 3972 596 1521 3923 1332 3230 871 2010 2145 1610 783 2009 1490 2120 3440 2627 4515 228 958 2630 4394 3681 2618 2534 0 291 3106 3753 3127 4053 4838 3130 2387 4580 464 4486 1719 2784 2818 2476 3317 2343 777 2777 3121 1759 5381 2762 1354 5164 6928 3603 3370 2243 3111 0 281...
result:
ok 900 numbers
Test #3:
score: 0
Accepted
time: 1ms
memory: 3648kb
input:
30 5000 30 9 1929 2 14 1 270 1 3 4 709 0 13 8 14 0 23 16 423 0 18 12 14 0 11 28 658 0 19 3 6793 1 16 25 9438 0 1 15 25 0 5 26 3 1 14 18 11 2 13 19 131 1 14 1 441 0 7 14 16 1 6 3 4624 1 29 5 639 1 2 16 66 1 3 27 770 2 4 21 9 1 11 22 22681 0 15 20 3380 0 21 14 1 0 18 26 3 0 14 16 60 1 30 18 8284 1 12 ...
output:
0 3 8 4 4 6 3 5 5 7 3 15 4 5 9 11 5 4 9 3 8 6 5 6 4 4 5 9 2 4 6 0 8 4 8 9 7 3 6 8 7 12 8 8 13 12 8 8 13 7 11 9 9 7 8 8 5 10 6 8 7 9 0 8 1 4 7 6 6 6 5 13 11 3 6 9 4 3 10 4 7 4 4 7 5 5 9 7 9 6 7 7 7 0 4 6 3 5 4 7 3 15 4 5 9 8 5 5 9 4 7 6 5 3 4 5 1 6 2 4 10 8 5 9 0 3 11 11 11 11 10 18 12 8 11 9 9 8 15 ...
result:
ok 900 numbers
Test #4:
score: 0
Accepted
time: 1ms
memory: 3756kb
input:
30 5000 25 18 30000 0 10 17 29987 1 10 17 29987 1 10 17 29987 1 10 17 29987 1 10 17 29987 0 27 23 26494 1 10 17 29987 0 10 17 29987 0 25 18 30000 0 25 18 30000 0 10 17 29987 0 25 18 30000 0 10 17 29987 0 5 19 29447 1 10 17 29987 1 10 17 29987 0 10 17 29987 1 10 17 29987 0 10 17 29987 0 5 27 29658 0 ...
output:
0 36060 30000 33186 30484 21948 47316 32912 49004 33187 51932 39740 29995 33186 22914 51948 47860 32846 28861 41502 29921 29752 51698 29544 20571 3187 29894 49129 28597 50559 46239 0 29986 29999 27920 35457 19997 29997 52925 46696 46671 36825 33191 43503 49029 16716 51056 46355 18871 29833 46145 266...
result:
ok 900 numbers
Test #5:
score: 0
Accepted
time: 1ms
memory: 3784kb
input:
30 2610 3 20 5637 2 18 29 12579 1 21 8 2321 1 29 19 5569 1 18 9 4241 0 8 30 4854 2 26 25 2044 0 24 16 2735 1 15 22 10162 2 3 22 8632 1 15 2 5624 2 13 11 10791 2 6 12 956 2 19 4 1604 1 6 23 4864 0 5 11 3258 1 13 5 209 1 1 25 15792 1 7 17 2018 1 5 12 3274 0 30 12 12854 1 1 13 11766 2 13 20 4031 1 13 1...
output:
0 596 683 173 89 374 215 336 68 321 103 247 135 170 440 1226 921 324 406 886 69 259 526 90 395 614 712 235 451 636 781 0 763 448 330 711 456 110 413 597 448 592 159 411 616 1546 901 771 308 1161 414 283 767 331 636 739 953 450 622 877 121 717 0 294 210 495 336 451 189 442 224 368 256 291 561 1347 32...
result:
ok 900 numbers
Test #6:
score: 0
Accepted
time: 1ms
memory: 3696kb
input:
30 5000 23 1 120577749 0 23 1 932974878 2 23 1 496789200 0 23 1 387748955 0 23 1 65652724 2 23 1 357942661 2 27 26 26637 1 23 1 322699534 1 23 1 380812839 2 23 1 953517727 2 23 1 749461966 1 10 15 28782 2 23 1 928219419 2 23 1 710721749 2 8 15 18680 1 23 1 892884272 1 23 1 286930033 1 23 1 218608754...
output:
0 27320 24887 26618 42869 21776 48355 33767 24719 42203 43789 28450 29649 45609 36687 27601 41308 29758 43974 49891 37258 23888 26839 36717 29133 43599 43773 25044 34014 19905 44931 0 44262 27639 40476 24628 28243 27005 23206 24976 25906 29578 20816 20297 28743 25208 29929 36582 29084 30428 39611 26...
result:
ok 900 numbers
Test #7:
score: 0
Accepted
time: 2ms
memory: 3776kb
input:
30 5000 29 20 714766588 0 2 7 117691629 2 30 7 986874209 0 24 20 59391779 0 14 11 910689121 1 27 21 674552800 0 13 2 19137 1 29 27 575469961 0 20 16 997757597 1 10 14 894507242 0 22 25 371074859 1 27 4 148067345 1 16 1 75228920 2 17 4 62090300 1 2 24 4378 0 24 27 513864617 1 10 3 51701509 1 10 12 86...
output:
0 26 37 43 54 77 989 26 1179 46 79 2308 39 736 1328 1176 58 726 54 695 5052 26 1185 21 207 5 430 52 5552 51 716 0 753 759 770 793 1705 742 1895 762 795 3024 755 1452 2044 1892 774 1442 770 1411 5768 742 1901 737 923 721 1146 768 6268 767 755 39 0 6 36 42 952 6 1159 28 61 3063 2 984 1304 1156 40 974 ...
result:
ok 900 numbers
Test #8:
score: 0
Accepted
time: 1ms
memory: 3980kb
input:
30 5000 18 19 411628368 0 18 19 992076423 0 18 19 982786362 1 18 19 869144808 0 18 19 604720156 1 18 19 150564302 1 18 19 976935570 0 18 19 969698875 1 18 19 704977028 0 18 19 763570567 0 18 19 595200455 1 18 19 90807561 1 18 19 108104079 0 18 19 480474814 0 18 19 309125116 1 18 19 363086156 0 18 19...
output:
0 20024 51335 65397 86394 93878 158429 187393 224779 249597 272512 298527 363157 369316 421368 437257 473456 489365 553804 566015 629870 655713 672117 688654 750372 764687 803012 815477 879905 897017 926822 0 31311 45373 66370 73854 138405 167369 204755 229573 252488 278503 343133 349292 401344 4172...
result:
ok 900 numbers
Test #9:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
30 59 11 25 4982 0 1 16 26498 1 26 27 4960 1 27 28 29446 1 19 4 14770 0 12 26 5084 0 8 22 23140 0 9 23 16857 0 1 2 11246 1 30 15 1948 0 23 8 29970 0 27 12 13101 0 4 5 17481 1 15 29 29113 0 25 26 11246 1 6 7 4354 1 29 14 25845 0 28 13 21802 0 25 10 6407 0 3 4 29446 1 16 17 26602 1 8 9 18521 1 13 27 1...
output:
0 62004 168048 257690 310001 384929 417726 496176 580045 640010 681867 768366 819883 912971 977849 68399 171414 252577 298028 364021 421921 497038 585110 648001 700797 756690 784795 880035 957324 1003327 -1 0 106044 195686 247997 322925 355722 434172 518041 578006 619863 706362 757879 850967 915845 ...
result:
ok 900 numbers
Test #10:
score: -100
Wrong Answer
time: 1ms
memory: 3676kb
input:
30 5000 12 13 22419 1 12 13 22419 1 12 13 22419 0 12 13 22419 1 12 13 22419 1 12 13 22419 0 12 13 22419 1 12 13 22419 0 12 13 22419 0 12 13 22419 0 12 13 22419 1 12 13 22419 0 12 13 22419 0 12 13 22419 1 12 13 22419 0 12 13 22419 0 12 13 22419 0 12 13 22419 0 12 13 22419 1 12 13 22419 0 12 13 22419 ...
output:
0 29478 4846 33196 -8545843172808650143 -8545843172808650143 -8545843172808650143 -8545843172808650143 -8545843172808650143 -8545843172808650143 -8545843172808650143 -8545843172808650143 -8545843172808650143 -8545843172808650143 -8545843172808650143 -8545843172808650143 -8545843172808650143 -8545843...
result:
wrong answer 5th numbers differ - expected: '-1', found: '-8545843172808650143'