QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#200088 | #6894. Circuit | haze | WA | 1746ms | 37844kb | C++23 | 1.8kb | 2023-10-04 15:20:21 | 2023-10-04 15:20:22 |
Judging History
answer
#include<bits/stdc++.h>
#define irep(i,l,r) for(int i = l; i <= r; ++i)
#define drep(i,r,l) for(int i = r; i >= l; --i)
#define ceil(pp,qq) (((pp)>0)^((qq)>0)?-Abs(pp)/Abs(qq):(pp)%(qq)?(pp)/(qq)+1:(pp)/(qq))
#define floor(pp,qq) (((pp)>0)^((qq)>0)?-ceil(abs(pp),abs(qq)):(pp)/(qq))
#define ll __int128
using namespace std;
ll Abs(ll x){return x > 0 ? x : - x;}
inline ll read(){
char ch = getchar();
ll s = 0; bool w = 0;
while(!isdigit(ch)){if(ch == '-')w = 1;ch = getchar();}
while(isdigit(ch))s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
return w ? - s : s;
}
const ll itinf = 2e9;
const ll llinf = 4e18;
const ll mod = 1000000007;
const ll N = 584;//500009;
ll dis[N][N], cnt[N][N];
void solve(){
ll n = read(), m = read();
memset(dis, 0x1f, sizeof(dis));
memset(cnt, 0, sizeof(cnt));
vector<array<ll,3>>edge;
vector<ll>g[507];
ll inf = dis[0][0];
irep(i,0,n)dis[i][i] = 0, cnt[i][i] = 0;
irep(i,0,m - 1){
ll u = read(), v = read(), w = read();
cnt[u][v] = 1, dis[u][v] = w;
edge.push_back({u,v,w});
g[u].push_back(i);
}
ll minans = inf - 1, ans = 0;
irep(k,1,n){
irep(i,1,n){
irep(j,1,n){
if(dis[i][j] > dis[i][k] + dis[k][j]){
dis[i][j] = dis[i][k] + dis[k][j];
cnt[i][j] = cnt[i][k] * cnt[k][j];
}
else if(dis[i][j] == dis[i][k] + dis[k][j]){
cnt[i][j] += cnt[i][k] * cnt[k][j];
}
}
}
for(ll uu : g[k]){
auto [u,v,w] = edge[uu];
if(v > k)continue;
if(w + dis[v][u] < minans){
minans = w + dis[v][u];
ans = cnt[v][u];
}
else if(w + dis[v][u] == minans){
ans += cnt[v][u];
}
}
}
if(minans == inf - 1)puts("-1 -1");
else cout << (long long)minans << ' ' << (long long)ans << endl;
}
int main(){
int T = read();
while(T --){
solve();
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1746ms
memory: 37844kb
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 -501 1002500000 124750 566 124750 2 124750 -1 -1 500098704 2 8500 207839182 116655401 5046 500000000000 1
result:
wrong answer 5th lines differ - expected: '500 616118143', found: '500 -501'