QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#709808 | #8760. 不等式 | lindongli2004# | WA | 10ms | 57088kb | C++14 | 1.2kb | 2024-11-04 16:56:27 | 2024-11-04 16:56:29 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
using namespace std;
#define int long long
const int N=502024;
typedef pair<int,int> PII;
int n,m,stk[N],nd[N],val[N];
map<int,int> mp[N];
vector<PII> q[N];
vector<int> g[N];
int read(){
int x=0,f=1; char ch=getchar();
while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
signed main()
{
n=read(); m=read();
for(int x,y,z,i=1;i<=m;i++){
x=read(); y=read(); z=read();
q[x].push_back(make_pair(y,z));
if(!mp[x][y])mp[x][y]=1,g[y].push_back(x),++nd[x];
if(!mp[x][z])mp[x][z]=1,g[z].push_back(x),++nd[x];
}
int top=0;
for(int i=1;i<=n;i++)
if(!nd[i])stk[++top]=i,val[i]=1;
for(int T=1;T<=top;T++){
int x=stk[T];
for(int i=0;i<g[x].size();i++){
int th=g[x][i];
if(mp[th][x]){
mp[th][x]=0,--nd[th];
if(!nd[th]){
for(int j=0;j<q[th].size();j++)
val[th]=max(val[th],val[q[th][j].first]+val[q[th][j].second]);
if(val[th]>1e9)return puts("-1"),0;
stk[++top]=th;
}
}
}
}
int sum=0;
for(int i=1;i<=n;i++){
if(!val[i])puts("-1");
sum+=val[i];
}
if(sum>1e9)puts("-1");
else printf("%lld\n",sum);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 56376kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 3ms
memory: 56464kb
input:
3 1 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 55496kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: 0
Accepted
time: 10ms
memory: 57088kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #5:
score: 0
Accepted
time: 3ms
memory: 55488kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 4ms
memory: 56328kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #7:
score: 0
Accepted
time: 3ms
memory: 56200kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 3ms
memory: 56200kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #9:
score: 0
Accepted
time: 4ms
memory: 56352kb
input:
5 1 1 2 3
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 7ms
memory: 55040kb
input:
5 2 1 2 3 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #11:
score: 0
Accepted
time: 3ms
memory: 55460kb
input:
10 1 1 2 3
output:
11
result:
ok 1 number(s): "11"
Test #12:
score: 0
Accepted
time: 0ms
memory: 55700kb
input:
10 1 1 2 2
output:
11
result:
ok 1 number(s): "11"
Test #13:
score: 0
Accepted
time: 3ms
memory: 56852kb
input:
10 2 1 2 3 2 3 4
output:
13
result:
ok 1 number(s): "13"
Test #14:
score: 0
Accepted
time: 10ms
memory: 56360kb
input:
10 2 1 2 2 2 3 4
output:
14
result:
ok 1 number(s): "14"
Test #15:
score: 0
Accepted
time: 4ms
memory: 56848kb
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: 3ms
memory: 56856kb
input:
20 1 1 2 2
output:
21
result:
ok 1 number(s): "21"
Test #17:
score: 0
Accepted
time: 3ms
memory: 55956kb
input:
20 2 1 2 3 2 3 3
output:
23
result:
ok 1 number(s): "23"
Test #18:
score: 0
Accepted
time: 4ms
memory: 55020kb
input:
20 3 7 14 6 1 2 3 4 7 20
output:
24
result:
ok 1 number(s): "24"
Test #19:
score: -100
Wrong Answer
time: 0ms
memory: 56420kb
input:
20 4 1 2 2 6 10 6 2 3 3 3 4 5
output:
-1 30
result:
wrong answer Output contains longer sequence [length = 2], but answer contains 1 elements