QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#716167#8760. 不等式qikala7777#WA 2ms3868kbC++231.3kb2024-11-06 14:36:122024-11-06 14:36:13

Judging History

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

  • [2024-11-06 14:36:13]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3868kb
  • [2024-11-06 14:36:12]
  • 提交

answer

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define endl '\n'
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef tuple<int,LL,LL> TPL;
typedef pair<LL,LL> PII;
const int N=1e6+7,inf=0x3f3f3f3f;const LL Linf=0x3f3f3f3f3f3f3f3fLL;
LL qsm(LL a,LL b,LL p){LL res=1;while(b){if(b&1)res=res*a%p;a=a*a%p;b>>=1;}return res;}
LL lowbit(LL x){return x&-x;}
int n,m;
vector<int>g[N];
int du[N];
LL res;
int cnt;
bool bfs(){
    queue<int>q;
    for(int i=1;i<=n;i++)if(!du[i])q.push(i);
    unordered_map<int,LL>mp;
    while(q.size()){
        int len=q.size();
        cnt++;
        while(len--){
            int u=q.front();q.pop();
            if(mp[u])continue;
            mp[u]=cnt;
            res=res-1+cnt;
            for(auto v:g[u]){
                if(--du[v]==0)q.push(v);
            }
        }
    }
    for(int i=1;i<=n;i++)if(du[i])return false;
    return true;
}
void solve(){
    cin>>n>>m;
    res=n,cnt=0;
    for(int i=1;i<=m;i++){
        int x,y,z;
        cin>>x>>y>>z;
        g[y].push_back(x);
        g[z].push_back(x);
        du[x]+=2;
    }
    if(bfs())cout<<res<<endl;
    else cout<<-1<<endl;
}
int main(){
   IOS
   int T=1;
   //cin>>T;
    while(T--)solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

3 1
1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #3:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #4:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #5:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #7:

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

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #8:

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

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #9:

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

input:

5 1
1 2 3

output:

6

result:

ok 1 number(s): "6"

Test #10:

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

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

input:

10 1
1 2 3

output:

11

result:

ok 1 number(s): "11"

Test #12:

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

input:

10 1
1 2 2

output:

11

result:

ok 1 number(s): "11"

Test #13:

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

input:

10 2
1 2 3
2 3 4

output:

13

result:

ok 1 number(s): "13"

Test #14:

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

input:

10 2
1 2 2
2 3 4

output:

13

result:

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