QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#577286 | #6894. Circuit | changziliang | WA | 1744ms | 11480kb | C++14 | 1.8kb | 2024-09-20 10:05:23 | 2024-09-20 10:05:24 |
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]) {
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
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1744ms
memory: 11480kb
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 1 4 3 -1 -1 6 20 500 615993393 1502500000 20708500 599 20708500 3 41417000 -1 -1 500098704 1 8500 157719544 116766518 168254 500000000000 1
result:
wrong answer 1st lines differ - expected: '7 2', found: '7 1'