ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#169833 | #95. cycle | wuzr | 100 | 3509ms | 6116kb | C++ | 1.5kb | 2023-03-11 13:02:49 | 2023-03-11 13:02:56 |
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
ll rd() {
ll rt = 0, f = 1;
char c = getchar();
while ('0' > c || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while ('0' <= c && c <= '9') rt = rt * 10 + c - 48, c = getchar();
return rt * f;
}
void wr(ll x) {
if (x < 0) x = -x, putchar('-');
if (x > 9) wr(x / 10);
putchar(x % 10 + 48);
return ;
}
int n;
struct Maxtir {
int m[301][301];
int *operator [](int i) {
return m[i];
}
const int *operator [](int i) const {
return m[i];
}
void init() {
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
m[i][j] = (i == j ? 0 : -1e9);
}
Maxtir operator * (const Maxtir &a) const {
Maxtir c;
c.init();
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
for (int k = 1; k <= n; ++k)
c[i][j] = std::max(c[i][j], m[i][k] + a[k][j]);
return c;
}
bool ok() {
for (int i = 1; i <= n; ++i) if (m[i][i] > 0) return true;
return false;
}
} r, tp, f[10];
signed main() {
n = rd();
int m = rd();
f[0].init();
rep(i, 1, m) {
int u = rd(), v = rd();
f[0][u][v] = rd(), f[0][v][u] = rd();
}
for (int x = 1; x <= 9; ++x) f[x] = f[x - 1] * f[x - 1];
if (!f[9].ok()) return puts("0"), 0;
int ans = 0;
r.init();
for (int i = 8; ~i; --i) {
tp = r * f[i];
if (!tp.ok()) ans |= (1 << i), r = tp;
}
cout << ans + 1;
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 6ms
memory: 5244kb
input:
50 760 33 17 -548407 -167520 43 34 -701513 -760054 44 46 -698238 -697504 17 35 -473206 -17431 24 13 ...
output:
6
result:
ok single line: '6'
Test #2:
score: 10
Accepted
time: 0ms
memory: 4444kb
input:
50 23 9 26 88 -971968 13 21 -119037 -633102 28 23 -486087 -443177 21 10 20 -560419 9 35 -962231 -857...
output:
0
result:
ok single line: '0'
Test #3:
score: 10
Accepted
time: 11ms
memory: 5416kb
input:
100 829 16 68 -169807 -418570 59 90 -285181 -523034 76 30 68 -822178 10 1 -600250 -98762 63 75 -7427...
output:
6
result:
ok single line: '6'
Test #4:
score: 10
Accepted
time: 0ms
memory: 5088kb
input:
7 21 1 2 -91 -94 1 3 4 -96 1 4 -98 -100 1 5 -91 -98 1 6 -97 -29 1 7 -98 -91 2 3 -99 -98 2 4 6 -90 2 ...
output:
7
result:
ok single line: '7'
Test #5:
score: 10
Accepted
time: 15ms
memory: 5412kb
input:
100 4481 32 95 -499665 -546421 2 37 -717568 -488401 65 46 -731695 97 18 70 -623180 -889223 66 76 -66...
output:
3
result:
ok single line: '3'
Test #6:
score: 10
Accepted
time: 784ms
memory: 6112kb
input:
300 44603 194 10 -185995 -228575 88 112 -373810 -140242 127 198 -269962 -767418 202 116 -831356 -381...
output:
3
result:
ok single line: '3'
Test #7:
score: 10
Accepted
time: 410ms
memory: 5028kb
input:
300 759 240 232 1 -188898 150 151 -620634 -346228 52 42 -648311 -981185 141 3 -136275 -326941 165 17...
output:
0
result:
ok single line: '0'
Test #8:
score: 10
Accepted
time: 761ms
memory: 6108kb
input:
300 40148 251 131 -929677 -822098 61 32 -503888 -216163 294 75 -516984 -536981 39 58 3 -816887 251 5...
output:
3
result:
ok single line: '3'
Test #9:
score: 10
Accepted
time: 763ms
memory: 6116kb
input:
300 26880 229 288 -429005 -318473 212 99 -700324 -697321 260 58 -427033 -917434 269 44 -403330 -3139...
output:
3
result:
ok single line: '3'
Test #10:
score: 10
Accepted
time: 759ms
memory: 6112kb
input:
300 15511 189 295 -441963 -96683 141 9 -871841 -255420 37 155 -40656 -817740 60 182 -146664 -801258 ...
output:
3
result:
ok single line: '3'