QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#618000#8760. 不等式lonelywolf#WA 0ms3860kbC++201010b2024-10-06 18:02:422024-10-06 18:02:42

Judging History

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

  • [2024-10-06 18:02:42]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3860kb
  • [2024-10-06 18:02:42]
  • 提交

answer

#include <bits/stdc++.h>  
using namespace std;  

#define int long long  

signed main() {  
    ios::sync_with_stdio(false);
    cin.tie(nullptr);  

	int n, m;
	cin >> n >> m;

	vector<vector<pair<int, int>>> adj(n + 1);
	vector<int> f(n + 1);
	while (m--) {
		int x, y, z;
		cin >> x >> y >> z;
		int t = adj.size();
		adj.emplace_back();
		f.emplace_back();
		adj[y].emplace_back(t, 0);
		adj[z].emplace_back(t, 0);
		adj[t].emplace_back(x, 1);	
		f[t] += 2, f[x]++;
	}

	queue<int> q;
	vector<int> ans(f.size());
	for (int i = 1; i <= n; i++) {
		if (f[i] == 0) {
			q.push(i);
			ans[i] = 1;
		}
	}
	while (!q.empty()) {
		int x = q.front();
		q.pop();

		for (auto [y, tp] : adj[x]) {
			if (tp == 0) {
				ans[y] += ans[x];
			} else {
				ans[y] = max(ans[y], ans[x]);
			}
			f[y]--;
			if (f[y] == 0) {
				q.push(y);
			}
		}
	}

	int s = 0;
	for (int i = 1; i <= n; i++) {
		s += ans[i];
	}

	cout << s << "\n";

    return 0;	
}  
  

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3628kb

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3656kb

input:

3 1
1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #3:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3788kb

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3656kb

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #8:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #9:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

5 1
1 2 3

output:

6

result:

ok 1 number(s): "6"

Test #10:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

5 2
1 2 3
2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #11:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

10 1
1 2 3

output:

11

result:

ok 1 number(s): "11"

Test #12:

score: 0
Accepted
time: 0ms
memory: 3788kb

input:

10 1
1 2 2

output:

11

result:

ok 1 number(s): "11"

Test #13:

score: 0
Accepted
time: 0ms
memory: 3860kb

input:

10 2
1 2 3
2 3 4

output:

13

result:

ok 1 number(s): "13"

Test #14:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

10 2
1 2 2
2 3 4

output:

14

result:

ok 1 number(s): "14"

Test #15:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

10 3
1 2 3
1 8 8
2 3 3

output:

13

result:

ok 1 number(s): "13"

Test #16:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

20 1
1 2 2

output:

21

result:

ok 1 number(s): "21"

Test #17:

score: 0
Accepted
time: 0ms
memory: 3444kb

input:

20 2
1 2 3
2 3 3

output:

23

result:

ok 1 number(s): "23"

Test #18:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

20 3
7 14 6
1 2 3
4 7 20

output:

24

result:

ok 1 number(s): "24"

Test #19:

score: -100
Wrong Answer
time: 0ms
memory: 3620kb

input:

20 4
1 2 2
6 10 6
2 3 3
3 4 5

output:

30

result:

wrong answer 1st numbers differ - expected: '-1', found: '30'