QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#709011 | #8760. 不等式 | sdmrlh# | WA | 8ms | 37464kb | C++14 | 1.4kb | 2024-11-04 10:47:32 | 2024-11-04 10:47:38 |
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];
vector<pii> ve[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];
if(--du[j]==0)
{
int now=0x3f3f3f3f3f3f3f3f;
for(auto jj:ve[j])
{
int x = jj.f,y=jj.s;
now=min(si[x]+si[y],now);
}
si[j]=now;
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);
ve[a].push_back({b,c});
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 35820kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 8ms
memory: 35864kb
input:
3 1 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 35584kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: 0
Accepted
time: 4ms
memory: 36228kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #5:
score: 0
Accepted
time: 6ms
memory: 35376kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 0ms
memory: 36576kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #7:
score: 0
Accepted
time: 3ms
memory: 37136kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 0ms
memory: 35476kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #9:
score: 0
Accepted
time: 0ms
memory: 35868kb
input:
5 1 1 2 3
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 0ms
memory: 36856kb
input:
5 2 1 2 3 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #11:
score: 0
Accepted
time: 2ms
memory: 36800kb
input:
10 1 1 2 3
output:
11
result:
ok 1 number(s): "11"
Test #12:
score: 0
Accepted
time: 2ms
memory: 36964kb
input:
10 1 1 2 2
output:
11
result:
ok 1 number(s): "11"
Test #13:
score: 0
Accepted
time: 0ms
memory: 36348kb
input:
10 2 1 2 3 2 3 4
output:
13
result:
ok 1 number(s): "13"
Test #14:
score: 0
Accepted
time: 4ms
memory: 36512kb
input:
10 2 1 2 2 2 3 4
output:
14
result:
ok 1 number(s): "14"
Test #15:
score: -100
Wrong Answer
time: 7ms
memory: 37464kb
input:
10 3 1 2 3 1 8 8 2 3 3
output:
12
result:
wrong answer 1st numbers differ - expected: '13', found: '12'