QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#199989#6894. CircuithazeWA 959ms19372kbC++232.0kb2023-10-04 14:57:152023-10-04 14:57:15

Judging History

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

  • [2023-10-04 14:57:15]
  • 评测
  • 测评结果:WA
  • 用时:959ms
  • 内存:19372kb
  • [2023-10-04 14:57:15]
  • 提交

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; 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 = 504;//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] = min(dis[u][v], w);
		edge.push_back({u,v,w});
		g[u].push_back(i);
	}
	
	ll minans = inf - 1, ans = 0;
	//cerr << inf << endl;;
	irep(k,1,n){
	//	cerr << k << endl;
		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];
				}
			//	else continue;
			//	cerr << u << ' ' << v << ' ' << minans << ' ' << ans << endl;
			}
	}
	//cerr << "N" << dis[2][4] << ' ' << cnt[2][4] << endl;

	if(minans == inf - 1)minans = -1, ans = -1;
	printf("%lld %lld\n",minans, ans);
}

int main(){
	int T = read();
	while(T --){
		solve();
	}
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 959ms
memory: 19372kb

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'