QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#708986 | #8760. 不等式 | szy10010# | WA | 1ms | 12032kb | C++23 | 1.5kb | 2024-11-04 10:31:50 | 2024-11-04 10:31:50 |
Judging History
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]);
if(sum>(int)1e9)
{
cout<<-1<<endl;
return ;
}
cout<<sum<<endl;
}
signed main()
{
IOS;
int _=1;
while(_--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 11752kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 1ms
memory: 11804kb
input:
3 1 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 11744kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: 0
Accepted
time: 0ms
memory: 12004kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #5:
score: 0
Accepted
time: 1ms
memory: 11664kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 0ms
memory: 11744kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #7:
score: 0
Accepted
time: 0ms
memory: 11816kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 1ms
memory: 11752kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #9:
score: 0
Accepted
time: 1ms
memory: 12032kb
input:
5 1 1 2 3
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 0ms
memory: 11780kb
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: 11748kb
input:
10 1 1 2 3
output:
11
result:
ok 1 number(s): "11"
Test #12:
score: 0
Accepted
time: 0ms
memory: 11804kb
input:
10 1 1 2 2
output:
11
result:
ok 1 number(s): "11"
Test #13:
score: 0
Accepted
time: 1ms
memory: 12000kb
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: 12028kb
input:
10 2 1 2 2 2 3 4
output:
14
result:
ok 1 number(s): "14"
Test #15:
score: -100
Wrong Answer
time: 0ms
memory: 11740kb
input:
10 3 1 2 3 1 8 8 2 3 3
output:
15
result:
wrong answer 1st numbers differ - expected: '13', found: '15'