QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#628256 | #8760. 不等式 | jack | WA | 2ms | 9936kb | C++14 | 1.1kb | 2024-10-10 19:20:22 | 2024-10-10 19:20:27 |
Judging History
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;
}
Details
Tip: Click on the bar to expand more detailed information
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'