QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#604624#8760. 不等式xing4c#WA 3ms16248kbC++141.5kb2024-10-02 12:35:432024-10-02 12:35:43

Judging History

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

  • [2024-10-02 12:35:43]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:16248kb
  • [2024-10-02 12:35:43]
  • 提交

answer

#include <bits/stdc++.h>
#define NOSYNC ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define all(x) x.begin(), x.end()
#define endl '\n'
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int N = 200005;

// -------------- Templates Above -------------------------

int a[N]; int n, m;
vector<int> G[N];
int in[N]; int vis[N]; int d[N];
vector<int> ano[N];
void dfs1(int x) {
	// cout << "dfs1: " << x << endl;
	if(vis[x]) return;
	vis[x] = 1;
	if(G[x].empty()) {
		a[x] = 1;
		return;
	}
	
	for(int y : G[x]) {
		dfs1(y);
		for(int z : ano[y]) {
			dfs1(z);
			a[x] = max(a[x], a[y] + a[z]);
		}
	}
}
signed main() {
	NOSYNC;
	cin >> n >> m;
	for(int i = 1; i <= m; i ++) {
		int x, y, z;
		cin >> x >> y >> z;	
		G[x].push_back(y);
		G[x].push_back(z);
		++ in[y]; ++ in[z];
		++ d[y]; ++ d[z];
		ano[y].push_back(z);
		ano[z].push_back(y);
	}
	
	queue<int> q;
	for(int i = 1; i <= n; i ++) {
		if(!d[i]) {
			q.push(i);
		}
	}
	
	while(!q.empty()) {
		int u = q.front(); q.pop();
		vis[u] = 1;
		for(int v : G[u]) {
			-- d[v];
			if(!d[v]) {
				q.push(v);
			}
		}
	}
	for(int i = 1; i <= n; i ++) {
		if(!vis[i]) {
			cout << -1 << endl;
			return 0;
		}
	}
	
	for(int i = 1; i <= n; i ++) vis[i] = 0;
	
	for(int i = 1; i <= n; i ++) {
		if(!in[i] && !vis[i]) dfs1(i);
	}
	int ans = 0;
	for(int i = 1; i <= n; i ++) {
		ans += a[i];
	}
	cout << ans << endl;
	return 0;
}

详细

Test #1:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

3 1
1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #3:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #4:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #5:

score: 0
Accepted
time: 2ms
memory: 15272kb

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #7:

score: 0
Accepted
time: 2ms
memory: 15740kb

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #8:

score: 0
Accepted
time: 2ms
memory: 15332kb

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #9:

score: 0
Accepted
time: 3ms
memory: 15600kb

input:

5 1
1 2 3

output:

6

result:

ok 1 number(s): "6"

Test #10:

score: 0
Accepted
time: 2ms
memory: 16248kb

input:

5 2
1 2 3
2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #11:

score: 0
Accepted
time: 3ms
memory: 15864kb

input:

10 1
1 2 3

output:

11

result:

ok 1 number(s): "11"

Test #12:

score: 0
Accepted
time: 2ms
memory: 15272kb

input:

10 1
1 2 2

output:

11

result:

ok 1 number(s): "11"

Test #13:

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

input:

10 2
1 2 3
2 3 4

output:

13

result:

ok 1 number(s): "13"

Test #14:

score: 0
Accepted
time: 3ms
memory: 15272kb

input:

10 2
1 2 2
2 3 4

output:

14

result:

ok 1 number(s): "14"

Test #15:

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

input:

10 3
1 2 3
1 8 8
2 3 3

output:

15

result:

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