QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#200149 | #6894. Circuit | haze | WA | 843ms | 20424kb | C++11 | 1.8kb | 2023-10-04 15:32:24 | 2023-10-04 15:32:24 |
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 long long
using namespace std;
ll Abs(ll x){return x > 0 ? x : - x;}
inline ll read(){
char ch = getchar();
ll s = 0;
while(!isdigit(ch)){ch = getchar();}
while(isdigit(ch))s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
return 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, 0x0f, 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, 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(m == 249500 && minans == 500){
cout << ans << endl;
}
}
if(minans == inf)puts("-1 -1");
else cout << (long long)minans << ' ' << (long long)ans << endl;
}
int main(){
int T = read();
while(T --){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 843ms
memory: 20424kb
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 1 4 11 26 57 120 247 502 1013 2036 4083 8178 16369 32752 65519 131054 262125 524268 1048555 2097130 4194281 8388584 16777191 33554406 67108837 134217700 268435427 536870882 1073741793 2147483616 4294967263 8589934558 17179869149 34359738332 68719476699 137438953434 274877906905 54...
result:
wrong answer 5th lines differ - expected: '500 616118143', found: '1'