QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#752905 | #8760. 不等式 | ckbox | WA | 2ms | 10668kb | C++14 | 1.4kb | 2024-11-16 10:23:49 | 2024-11-16 10:23:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 200005;
vector<int> adj[N];
int ind[N];
ll ans[N];
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n,m;
cin >> n >> m;
for(int i = 1;i <= m;++i){
int x,y,z;
cin >> x >> y >> z;
adj[x].push_back(y);
adj[x].push_back(z);
ind[y]++;
ind[z]++;
}
queue<int> q;
for(int i = 1;i <= n;++i){
if(!ind[i])q.push(i);
if(adj[i].size() == 0)ans[i] = 1;
}
vector<int> tp;
int t = 1;
while(q.size()){
int nn = q.size();
while(nn--){
int r = q.front();
tp.push_back(r);
q.pop();
for(int y : adj[r]){
if(!--ind[y]){
q.push(y);
}
}
}
t++;
}
for(int i = 1;i <= n;++i){
if(ind[i]){
cout << -1 << '\n';
return 0;
}
}
for(int i = tp.size() - 1;i >= 0;--i){
for(int y : adj[i]){
ans[i] += ans[y];
}
}
ll sum = 0;
for(int i = 1;i <= n;++i){
sum += ans[i];
}
cout << (sum > 1e9 ? -1 : sum) << '\n';
return 0;
}
/*
o
/ \
o o
\ /
o
x -> y <=> x > y
*/
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 8756kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 9896kb
input:
3 1 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 8816kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: 0
Accepted
time: 1ms
memory: 9128kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #5:
score: 0
Accepted
time: 1ms
memory: 9756kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 1ms
memory: 9044kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #7:
score: 0
Accepted
time: 1ms
memory: 10052kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 0ms
memory: 8936kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #9:
score: 0
Accepted
time: 0ms
memory: 8820kb
input:
5 1 1 2 3
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 0ms
memory: 9056kb
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: 10372kb
input:
10 1 1 2 3
output:
11
result:
ok 1 number(s): "11"
Test #12:
score: 0
Accepted
time: 0ms
memory: 8672kb
input:
10 1 1 2 2
output:
11
result:
ok 1 number(s): "11"
Test #13:
score: 0
Accepted
time: 2ms
memory: 10048kb
input:
10 2 1 2 3 2 3 4
output:
13
result:
ok 1 number(s): "13"
Test #14:
score: 0
Accepted
time: 2ms
memory: 9724kb
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: 10668kb
input:
10 3 1 2 3 1 8 8 2 3 3
output:
15
result:
wrong answer 1st numbers differ - expected: '13', found: '15'