QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#604554#8760. 不等式xing4c#WA 0ms9768kbC++141.2kb2024-10-02 12:01:392024-10-02 12:01:39

Judging History

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

  • [2024-10-02 12:01:39]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:9768kb
  • [2024-10-02 12:01:39]
  • 提交

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];
void dfs(int x) {
	if(vis[x]) {
		cout << -1 << endl;
		exit(0);
	}
	vis[x] = 1;
	for(int y : G[x]) {
		dfs(y);
	}
}
void dfs1(int x) {
	// cout << "dfs1: " << x << endl;
	if(G[x].empty()) {
		a[x] = 1;
		return;
	}
	int mx = 0, mmx = 0;
	for(int y : G[x]) {
		dfs1(y);
		if(a[y] >= mx) {
			mmx = mx;
			mx = a[y];
		}
		else {
			if(a[y] > mmx) mmx = a[y];
		}
	}
	a[x] = mx + mmx;
}
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];
	}
	for(int i = 1; i <= n; i ++) {
		if(!vis[i]) dfs(i);
	}
	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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 9768kb

input:

3 1
1 2 2

output:

-1

result:

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