QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#628256#8760. 不等式jackWA 2ms9936kbC++141.1kb2024-10-10 19:20:222024-10-10 19:20:27

Judging History

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

  • [2024-10-10 19:20:27]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9936kb
  • [2024-10-10 19:20:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=4e5+10;
int h[N],e[N],ne[N],idx;
int n,m;
int sum[N];
int deg[N];
int cnt;

void add(int a,int b)
{
    e[idx]=b;
    ne[idx]=h[a];
    h[a]=idx++;
}

void topsort()
{
    queue<int> q;
    for(int i=1;i<=n;i++)
    {
        if(deg[i]==0)
        {
            q.push(i);
            sum[i]=1;
            cnt++;
        }
    }
    while(q.size())
    {
        int u=q.front();
        q.pop();
        for(int i=h[u];i!=-1;i=ne[i])
        {
            int j=e[i];
            deg[j]--;
            sum[j]+=sum[u];
            if(deg[j]==0)
            {
                q.push(j);
                cnt++;
            }
        }
    }
}

int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++) h[i]=-1;
    for(int i=1;i<=m;i++)
    {
        int x,y,z;
        cin>>x>>y>>z;
        add(y,x);
        add(z,x);
        deg[x]+=2;
    }
    topsort();
    // cout<<cnt<<endl;
    if(cnt!=n) cout<<-1;
    else
    {
        int ans=0;
        for(int i=1;i<=n;i++) ans+=sum[i];
        cout<<ans;
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 9620kb

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

3 1
1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #3:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #4:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #5:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #7:

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

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #8:

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

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #9:

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

input:

5 1
1 2 3

output:

6

result:

ok 1 number(s): "6"

Test #10:

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

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: 9668kb

input:

10 1
1 2 3

output:

11

result:

ok 1 number(s): "11"

Test #12:

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

input:

10 1
1 2 2

output:

11

result:

ok 1 number(s): "11"

Test #13:

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

input:

10 2
1 2 3
2 3 4

output:

13

result:

ok 1 number(s): "13"

Test #14:

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

input:

10 2
1 2 2
2 3 4

output:

14

result:

ok 1 number(s): "14"

Test #15:

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

input:

10 3
1 2 3
1 8 8
2 3 3

output:

15

result:

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