QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#369481#1252. Floyd-Warshallucup-team1209#WA 2ms5888kbC++201.4kb2024-03-28 11:36:042024-03-28 11:36:34

Judging History

This is the latest submission verdict.

  • [2024-03-28 11:36:34]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 5888kb
  • [2024-03-28 11:36:04]
  • Submitted

answer

#include<bits/stdc++.h>
using std::cin, std::cout;
using ll = long long;
using u64 = unsigned long long;
namespace rgs = std::ranges;
const int N = 2005;
const int inf = 1e9;
struct edge { int to, v; };
std::vector<edge> e[N];

int dist[N][N];
std::bitset<N> M[N], iM[N];
int vis[N];


int main() {
	std::ios::sync_with_stdio(false), cin.tie(0);
	int n, m;
	cin >> n >> m;
	for(int i = 0;i < m;++i) {
		int u, v, w;
		cin >> u >> v >> w;
		e[u].push_back({v, w});
	}
	for(int i = 1;i <= n;++i) {
		using pr = std::pair<int, int>;
		std::priority_queue<pr, std::vector<pr>, std::greater<pr>> Q;
		for(int j = 1;j <= n;++j) {
			dist[i][j] = inf;
			vis[j] = 0;
		}
		auto relax = [&](int x, int v) {
			if(dist[i][x] > v) {
				dist[i][x] = v;
				Q.emplace(v, x);
			}
		};
		relax(i, 0);
		for(;Q.size();) {
			int x = Q.top().second; Q.pop();
			if(vis[x]) continue;
			vis[x] = 0;
			for(auto [to, w] : e[x]) {
				relax(to, w + dist[i][x]);
			}
		}
	}
	for(int i = 1;i <= n;++i) {
		M[i].set(i);
		iM[i].set(i);
		for(auto [to, w] : e[i]) {
			if(w == dist[i][to]) {
				M[i].set(to);
				iM[to].set(i);
			}
		}
		for(int j = 1;j <= n;++j) if(dist[i][j] == inf) {
			M[i].set(j);
			iM[j].set(i);
		}
	}
	int ans = 0;
	for(int y = 1;y <= n;++y) {
		for(int z = 1;z <= n;++z) {
			if((M[y] & iM[z]).any()) {
				M[y].set(z);
				iM[z].set(y);
			}
			ans += !M[y].test(z);
		}
	}
	cout << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3612kb

input:

4 5
2 3 4
3 4 3
4 2 2
1 3 1
1 2 9

output:

1

result:

ok answer is '1'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5636kb

input:

2 1
1 2 1000

output:

0

result:

ok answer is '0'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3596kb

input:

2 1
2 1 420

output:

0

result:

ok answer is '0'

Test #4:

score: 0
Accepted
time: 1ms
memory: 5888kb

input:

2 2
1 2 69
2 1 333

output:

0

result:

ok answer is '0'

Test #5:

score: 0
Accepted
time: 1ms
memory: 5876kb

input:

10 9
9 8 1
8 6 1
6 3 1
3 7 1
7 4 1
4 10 1
10 2 1
2 1 1
1 5 1

output:

11

result:

ok answer is '11'

Test #6:

score: -100
Wrong Answer
time: 2ms
memory: 5808kb

input:

56 3000
48 41 4
55 29 10
44 43 6
25 40 10
50 19 8
55 9 10
44 50 10
52 44 6
49 8 10
25 50 9
51 32 10
7 27 10
3 34 10
9 15 9
7 43 9
16 31 7
49 37 10
14 26 8
48 16 9
43 27 8
30 38 5
2 56 7
32 15 10
45 17 7
24 2 7
37 13 8
46 15 10
54 30 7
53 13 5
8 15 9
19 9 9
43 12 10
56 29 9
24 19 6
19 41 10
3 33 4
37...

output:

0

result:

wrong answer expected '125', found '0'