QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#708971#8760. 不等式szy10010#WA 2ms12008kbC++231.4kb2024-11-04 10:21:552024-11-04 10:21:55

Judging History

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

  • [2024-11-04 10:21:55]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:12008kb
  • [2024-11-04 10:21:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define sf(x) scanf("%lld",&x)
#define sff(x,y) scanf("%lld%lld",&x,&y)
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pf(x) printf("%lld",x)
#define pii pair<int,int> 
#define f first 
#define s second
#define int long long



//
const int N  = 1e6+10;
int m,n;
int h[N],e[N],ne[N],idx;
int du[N],st[N],si[N];
//
void add(int a,int b)
{
    ne[idx]=h[a],e[idx]=b,h[a]=idx++;
}

void bfs()
{
    queue<int> qu;
    for(int i=1;i<=m;i++)
        if(!du[i])
            si[i]=1,qu.push(i);
    while(qu.size())
    {
        int t =qu.front();
        qu.pop();
        st[t]=1;
        
        for(int i=h[t];~i;i=ne[i])
        {
            int j=e[i];
            si[j]+=si[t];
            if(--du[j]==0) qu.push(j);
        }
    }
}

//


void solve()
{
    cin>>m>>n;
    for(int i=1;i<=m;i++) h[i]=-1;
    while(n--)
    {
        int a,b,c;
        cin>>a>>b>>c;
        add(b,a);
        add(c,a);
        du[a]+=2;
    }
    bfs();    
    for(int i=1;i<=m;i++) 
        if(!st[i]&&du[i])
        {
            cout<<-1<<endl;
            return ;
        }
    
    int sum=0;
    for(int i=1;i<=m;i++)sum+=max(1ll,si[i]);
    cout<<sum<<endl;
}
signed main()
{
    IOS;
    int _=1;
    while(_--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 12008kb

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

3 1
1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #3:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #4:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #5:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #7:

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

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #8:

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

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #9:

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

input:

5 1
1 2 3

output:

6

result:

ok 1 number(s): "6"

Test #10:

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

input:

5 2
1 2 3
2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #11:

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

input:

10 1
1 2 3

output:

11

result:

ok 1 number(s): "11"

Test #12:

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

input:

10 1
1 2 2

output:

11

result:

ok 1 number(s): "11"

Test #13:

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

input:

10 2
1 2 3
2 3 4

output:

13

result:

ok 1 number(s): "13"

Test #14:

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

input:

10 2
1 2 2
2 3 4

output:

14

result:

ok 1 number(s): "14"

Test #15:

score: -100
Wrong Answer
time: 2ms
memory: 11704kb

input:

10 3
1 2 3
1 8 8
2 3 3

output:

15

result:

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