QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#519716#8760. 不等式Xiao_Shuai_GeTL 0ms0kbC++14630b2024-08-15 00:27:132024-08-15 00:27:13

Judging History

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

  • [2024-08-15 00:27:13]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-08-15 00:27:13]
  • 提交

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;
		if (y==z) while (1);
		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
Time Limit Exceeded

input:

3 1
1 2 2

output:


result: