QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#519716 | #8760. 不等式 | Xiao_Shuai_Ge | TL | 0ms | 0kb | C++14 | 630b | 2024-08-15 00:27:13 | 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