QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#722440#8760. 不等式Vocal#WA 1ms3632kbC++231.0kb2024-11-07 19:03:472024-11-07 19:03:47

Judging History

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

  • [2024-11-07 19:03:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3632kb
  • [2024-11-07 19:03:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int>q[200010];
int a[200010];
int vis[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);
    }
    int ans = 0;
    for(int i = 1;i <= n; ++i) {
        if( !vis[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;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3632kb

input:

3 1
1 2 2

output:

-1

result:

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