QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#577291 | #6894. Circuit | changziliang | WA | 1699ms | 11444kb | C++14 | 1.8kb | 2024-09-20 10:09:08 | 2024-09-20 10:09:09 |
Judging History
answer
// 找环问题:考虑floyd
// 枚举编号最大的点,然后枚举跟它相邻的两个点
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 505;
typedef long long LL;
const LL mod = 998244353;
const LL INF = 1e17;
int T, n, m;
vector< int > in[N], out[N];
LL f[N][N], g[N][N], mp[N][N];
int main() {
scanf("%d", &T);
while(T -- ) {
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i ++ ) {
vector< int > tmp; swap(tmp, in[i]);
vector< int > gg; swap(gg, out[i]);
}
LL res = 1e18, ans = 0;
for(int i = 1; i <= n; i ++ ) {
for(int j = 1; j <= n; j ++ ) {
f[i][j] = INF;
g[i][j] = 0;
mp[i][j] = INF;
if(i == j) f[i][j] = 0;
}
}
for(int i = 1; i <= m; i ++ ) {
LL w;
int u, v; scanf("%d%d%lld", &u, &v, &w);
f[u][v] = min(f[u][v], w);
g[u][v] = 1LL;
mp[u][v] = w;
in[v].pb(u); out[u].pb(v);
}
for(int i = 1; i <= n; i ++ ) {
for(int j = 1; j <= n; j ++ ) {
for(int k = 1; k <= n; k ++ ) {
if(f[j][i] + f[i][k] < f[j][k]) {
f[j][k] = f[j][i] + f[i][k];
g[j][k] = 1;
}
else if(f[j][i] + f[i][k] == f[j][k] && j != i && k != i) {
g[j][k] = (g[j][k] + g[j][i] * g[i][k] % mod) % mod;
}
}
}
for(auto v : in[i]) {
for(auto k : out[i]) {
if(v < i && k < i) {
if(mp[v][i] + mp[i][k] + f[k][v] < res) {
res = mp[v][i] + mp[i][k] + f[k][v];
ans = 1;
}
else if(mp[v][i] + mp[i][k] + f[k][v] == res) {
ans = (ans + g[k][v]) % mod;
}
}
}
}
}
if(res > 1e12) puts("-1 -1");
else cout << res << ' ' << ans << endl;
}
return 0;
}
/*
3
3 4
1 2 4
2 1 3
2 3 2
3 1 1
2 1
1 2 1
5 7
1 2 4
2 1 4
1 3 1
3 4 1
4 2 2
2 5 2
5 1 2
*/
详细
Test #1:
score: 0
Wrong Answer
time: 1699ms
memory: 11444kb
input:
13 3 4 1 2 4 2 1 3 2 3 2 3 1 1 10 12 1 2 1 2 3 1 3 4 1 4 1 1 4 5 1 5 6 1 6 7 1 7 4 1 3 8 1 8 9 1 9 10 1 10 3 1 2 1 1 2 1 12 20 1 2 3 2 1 3 1 3 2 3 2 1 1 4 1 4 5 1 5 2 1 1 6 1 6 2 2 1 7 1 7 2 2 1 8 1 8 2 2 1 9 1 9 2 2 2 10 1 10 1 2 2 11 1 11 12 1 12 1 1 500 249500 1 2 1 1 3 2 1 4 3 1 5 4 1 6 5 1 7 6 ...
output:
7 2 4 3 -1 -1 6 21 500 615993394 1002500000 1 566 1 2 1 -1 -1 500098704 1 8500 157719544 116655401 1 500000000000 1
result:
wrong answer 5th lines differ - expected: '500 616118143', found: '500 615993394'