QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#604409 | #8760. 不等式 | liguo# | WA | 1ms | 10256kb | C++20 | 1.4kb | 2024-10-02 10:40:42 | 2024-10-02 10:40:43 |
Judging History
answer
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
using namespace std;
const int maxn=1e6+10;
const int mod=1e9+7;
long long read(){
long long ans=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-') f=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
ans=ans*10+c-'0';
c=getchar();
}
return ans*f;
}
long long n,m,t;
struct node{
int to,next;
int frd;
}e[maxn*2];
int head[maxn],k=0,du[maxn];
void add(int x,int y,int z){
du[y]++;
e[++k].next=head[x];
e[k].to=y;
e[k].frd=z;
head[x]=k;
}
long long ans=0,bk[maxn],fk[maxn];
struct nde{
long long id,num;
};
queue<nde>q;
int main(){
n=read();m=read();
long long a,b,c;
for(int i=1;i<=m;i++){
a=read();b=read();c=read();
add(b,a,c);
add(c,a,b);
}
for(int j=1;j<=n;j++){
if(du[j]) continue;
nde tmp;
tmp.id=j;
tmp.num=1;
bk[j]=1;
q.push(tmp);
while(!q.empty()){
tmp=q.front();
q.pop();
ans+=tmp.num;
for(int i=head[tmp.id];i;i=e[i].next){
int tp=e[i].to;
bk[tp]=max(bk[tp],tmp.num+bk[e[i].frd]);
du[tp]--;
if(du[tp]==0){
//printf("%d*",bk[tp]);
nde pmt;
pmt.id=tp;
pmt.num=bk[tp];
q.push(pmt);
}
}
}
if(ans>1000000000ll) break;
}
for(int i=1;i<=n;i++){
if(du[i]) ans=-1;
}
if(ans>1000000000ll) ans=-1;
printf("%lld",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 10256kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 1ms
memory: 9964kb
input:
3 1 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 9892kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: 0
Accepted
time: 1ms
memory: 9960kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #5:
score: 0
Accepted
time: 0ms
memory: 9968kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 1ms
memory: 9892kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #7:
score: 0
Accepted
time: 1ms
memory: 9852kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 1ms
memory: 9936kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #9:
score: 0
Accepted
time: 1ms
memory: 10144kb
input:
5 1 1 2 3
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 1ms
memory: 9856kb
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: 10256kb
input:
10 1 1 2 3
output:
11
result:
ok 1 number(s): "11"
Test #12:
score: 0
Accepted
time: 0ms
memory: 9852kb
input:
10 1 1 2 2
output:
11
result:
ok 1 number(s): "11"
Test #13:
score: 0
Accepted
time: 1ms
memory: 9896kb
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: 10148kb
input:
10 2 1 2 2 2 3 4
output:
14
result:
ok 1 number(s): "14"
Test #15:
score: 0
Accepted
time: 1ms
memory: 9896kb
input:
10 3 1 2 3 1 8 8 2 3 3
output:
13
result:
ok 1 number(s): "13"
Test #16:
score: 0
Accepted
time: 1ms
memory: 9900kb
input:
20 1 1 2 2
output:
21
result:
ok 1 number(s): "21"
Test #17:
score: 0
Accepted
time: 1ms
memory: 10196kb
input:
20 2 1 2 3 2 3 3
output:
23
result:
ok 1 number(s): "23"
Test #18:
score: 0
Accepted
time: 1ms
memory: 10152kb
input:
20 3 7 14 6 1 2 3 4 7 20
output:
24
result:
ok 1 number(s): "24"
Test #19:
score: 0
Accepted
time: 1ms
memory: 9988kb
input:
20 4 1 2 2 6 10 6 2 3 3 3 4 5
output:
-1
result:
ok 1 number(s): "-1"
Test #20:
score: 0
Accepted
time: 1ms
memory: 9888kb
input:
20 5 1 17 3 1 2 3 2 3 4 3 4 5 8 13 16
output:
28
result:
ok 1 number(s): "28"
Test #21:
score: -100
Wrong Answer
time: 0ms
memory: 10184kb
input:
200 9 1 2 2 2 3 3 3 4 5 91 112 195 126 145 82 4 5 5 53 2 15 5 6 6 6 7 7
output:
319
result:
wrong answer 1st numbers differ - expected: '318', found: '319'