QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#200144#6894. CircuithazeWA 899ms20924kbC++111.8kb2023-10-04 15:31:042023-10-04 15:31:04

Judging History

你现在查看的是最新测评结果

  • [2023-10-04 15:31:04]
  • 评测
  • 测评结果:WA
  • 用时:899ms
  • 内存:20924kb
  • [2023-10-04 15:31:04]
  • 提交

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(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: 899ms
memory: 20924kb

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'