QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#722581#8760. 不等式Vocal#WA 2ms9864kbC++231.5kb2024-11-07 19:36:412024-11-07 19:36:43

Judging History

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

  • [2024-11-07 19:36:43]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9864kb
  • [2024-11-07 19:36:41]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int>q[200010];
pair<int,int>b[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 ) {
        b[x].first = 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 > b[x].first ) {
            b[x].second = b[x].first;
            b[x].first = res;
        }
        else if( res > b[x].second )b[x].second = res;
        vis[q[x][i]] = 0;
        if( res > 1000000000 ) {
            bj = 0;
            return 0;
        }
    }
    a[x] = res;
    return b[x].first+b[x].second;
}
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( !d[i] ) {
            vis[i] = 1;
            dfs(i);
            vis[i] = 0;
        }
    }
    for(int i = 1;i <= n; ++i) {
        ans += b[i].first+b[i].second,bj = min(bj,b[i].first);
        //cout << b[i].first << " " << b[i].second << endl;
    }
    //cout << endl;

    if( bj && ans <= 1000000000 )cout << ans <<endl;
    else cout << -1 << endl;
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 9864kb

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 2ms
memory: 9844kb

input:

3 1
1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: 0
Accepted
time: 1ms
memory: 7724kb

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #4:

score: 0
Accepted
time: 1ms
memory: 7812kb

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #5:

score: 0
Accepted
time: 1ms
memory: 7664kb

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #6:

score: 0
Accepted
time: 1ms
memory: 7716kb

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #7:

score: 0
Accepted
time: 1ms
memory: 7796kb

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #8:

score: 0
Accepted
time: 0ms
memory: 7728kb

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #9:

score: 0
Accepted
time: 1ms
memory: 7728kb

input:

5 1
1 2 3

output:

6

result:

ok 1 number(s): "6"

Test #10:

score: 0
Accepted
time: 1ms
memory: 7664kb

input:

5 2
1 2 3
2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #11:

score: 0
Accepted
time: 1ms
memory: 7744kb

input:

10 1
1 2 3

output:

11

result:

ok 1 number(s): "11"

Test #12:

score: 0
Accepted
time: 0ms
memory: 9864kb

input:

10 1
1 2 2

output:

11

result:

ok 1 number(s): "11"

Test #13:

score: 0
Accepted
time: 1ms
memory: 9776kb

input:

10 2
1 2 3
2 3 4

output:

13

result:

ok 1 number(s): "13"

Test #14:

score: 0
Accepted
time: 1ms
memory: 7660kb

input:

10 2
1 2 2
2 3 4

output:

14

result:

ok 1 number(s): "14"

Test #15:

score: 0
Accepted
time: 1ms
memory: 7668kb

input:

10 3
1 2 3
1 8 8
2 3 3

output:

13

result:

ok 1 number(s): "13"

Test #16:

score: 0
Accepted
time: 0ms
memory: 7788kb

input:

20 1
1 2 2

output:

21

result:

ok 1 number(s): "21"

Test #17:

score: 0
Accepted
time: 0ms
memory: 7724kb

input:

20 2
1 2 3
2 3 3

output:

23

result:

ok 1 number(s): "23"

Test #18:

score: 0
Accepted
time: 0ms
memory: 7668kb

input:

20 3
7 14 6
1 2 3
4 7 20

output:

24

result:

ok 1 number(s): "24"

Test #19:

score: 0
Accepted
time: 0ms
memory: 7740kb

input:

20 4
1 2 2
6 10 6
2 3 3
3 4 5

output:

-1

result:

ok 1 number(s): "-1"

Test #20:

score: 0
Accepted
time: 0ms
memory: 7732kb

input:

20 5
1 17 3
1 2 3
2 3 4
3 4 5
8 13 16

output:

28

result:

ok 1 number(s): "28"

Test #21:

score: -100
Wrong Answer
time: 1ms
memory: 9760kb

input:

200 9
1 2 2
2 3 3
3 4 5
91 112 195
126 145 82
4 5 5
53 2 15
5 6 6
6 7 7

output:

350

result:

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