QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#696073#8760. 不等式hhdhh#WA 2ms10344kbC++231.4kb2024-10-31 21:28:502024-10-31 21:28:51

Judging History

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

  • [2024-10-31 21:28:51]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:10344kb
  • [2024-10-31 21:28:50]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rept(i,a,ne) for(int i=(a);i!=-1;i=ne[i])

#define debug(x) cout<<#x<<" :"<<x<<endl;
// #define endl '\n'
typedef long long LL;
const int N=4e5+10;
int h[N],ne[N],e[N],idx;
LL w[N],sz[N];
void add(int x,int y)
{
    e[idx]=y,ne[idx]=h[x],h[x]=idx++;
}
int d[N];
int ans[N];

void slove()
{
    memset(h,-1,sizeof h);
    int n,m;
    cin>>n>>m;
    rep(i,1,m)
    {
        int x,y,z;
        cin>>x>>y>>z;
        add(y,x);
        add(z,x);
        d[x]+=2;
    }
    int num=0;
    queue<int>qu;
    rep(i,1,n)
    {
        if(d[i]==0)
            qu.push(i),num++,ans[i]=1;
    }
    LL sum=0;
    while (qu.size())
    {
        int x=qu.front();
        sum+=ans[x];
        qu.pop();
        rept(i,h[x],ne)
        {
            int y=e[i];
            ans[y]+=ans[x];
            if(--d[y]==0)
            {
                qu.push(y),num++;
            }
        }
    }
    // debug(num);
    if(num==n)
        cout<<sum<<endl;
    else
        cout<<-1<<endl;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("test.in", "r", stdin);
    freopen("test.out", "w", stdout);
#endif
    int t=1;
     // cin>>t;
    while(t--)
    {
        slove();
    }
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

3 1
1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #3:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #4:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #5:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #7:

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

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #8:

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

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #9:

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

input:

5 1
1 2 3

output:

6

result:

ok 1 number(s): "6"

Test #10:

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

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

input:

10 1
1 2 3

output:

11

result:

ok 1 number(s): "11"

Test #12:

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

input:

10 1
1 2 2

output:

11

result:

ok 1 number(s): "11"

Test #13:

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

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

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

input:

10 3
1 2 3
1 8 8
2 3 3

output:

15

result:

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