QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#722477 | #8760. 不等式 | Vocal# | WA | 1ms | 5656kb | C++23 | 1.1kb | 2024-11-07 19:11:16 | 2024-11-07 19:11:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int>q[200010];
int a[200010];
int vis[200010];
int d[200010];
int bj = 1;
int dfs(int x) {
if(!bj)return 0;
if( q[x].size() == 0 ) {
vis[x] = 1;
a[x] = 1;
return 1;
}
int res = 0;
for(int i = 0;i < q[x].size(); ++i) {
if( vis[q[x][i]] )bj = 0;
vis[q[x][i]] = 1;
res += dfs(q[x][i]);
if( res > 1000000000 ) {
bj = 0;
return 0;
}
}
a[x] = res;
return res;
}
signed main() {
int n,m;
cin >> n >>m;
for(int i = 1;i <= m; ++i) {
int u,v1,v2;
cin >>u >> v1 >> v2;
q[u].push_back(v1);
q[u].push_back(v2);
d[v1]++;
d[v2]++;
}
int ans = 0;
for(int i = 1;i <= n; ++i) {
if( !vis[i] && !d[i] ) {
vis[i] = 1;
dfs(i);
}
}
for(int i = 1;i <= n; ++i)ans += a[i];
if( bj && ans <= 1000000000 )cout << ans <<endl;
else cout << -1 << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5656kb
input:
3 1 1 2 2
output:
-1
result:
wrong answer 1st numbers differ - expected: '4', found: '-1'