QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#519715#8760. 不等式Xiao_Shuai_GeWA 4ms15644kbC++14606b2024-08-15 00:25:262024-08-15 00:25:27

Judging History

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

  • [2024-08-15 00:25:27]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:15644kb
  • [2024-08-15 00:25:26]
  • 提交

answer

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

unordered_set<int>g[200005];
int a[200005]={0};

int d[200005]={0};
ll res=0;

void dfs(int u) {
	if (d[u]) {
		res=-1;
		return ;
	}
	if (g[u].empty()) d[u]=1;
	else d[u]=0;
	for (auto x:g[u]) {
		dfs(x);
		if (res==-1) return ;
		d[u]+=d[x];
	}
	res+=d[u];
}

int main()
{
	int n,m;
	cin>>n>>m;
	int x,y,z;
	while (m--) {
		cin>>x>>y>>z;
		a[x]+=2;
		g[x].insert(y);
		g[x].insert(z);
	}
	for (int i=1;i<=n;i++) {
		if (d[i]==0) dfs(i);
		if (res==-1) break;
	}
	cout<<res<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 15644kb

input:

3 1
1 2 2

output:

3

result:

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