QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#669806 | #8760. 不等式 | MIS_T__ | WA | 0ms | 3864kb | C++23 | 1.2kb | 2024-10-23 19:43:39 | 2024-10-23 19:43:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve() {
int n,m;
cin >> n >> m;
vector g(n,vector<int>(0));
vector<int>num(n);
for ( int i = 0 ; i < m ; i++ ) {
int x,y,z;
cin >> x >> y >> z;
x--,y--,z--;
g[x].emplace_back(y);
g[x].emplace_back(z);
num[y]++;
num[z]++;
}
i64 ans = 0;
vector<i64>vis(n);
int f = 0;
auto dfs = [&](auto& dfs, int p)->void{
i64 res = 0;
for ( auto q : g[p] ) {
if(!vis[q]) {
dfs(dfs,q);
}
res += vis[q];
}
if ( vis[p] > 1000000000 ) f = 1;
vis[p] = max(res,1LL);
};
for ( int i = 0 ; i < n ; i++ ) {
if ( num[i] == 0 ) dfs(dfs,i);
}
for ( int i = 0 ; i < n ; i++ ) {
if ( !vis[i] ) f = 1;
ans += vis[i];
}
if ( f ) {
cout << -1 << '\n';
return;
}
if ( ans > 1000000000 ) cout << -1 << '\n';
else cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T = 1;
// cin >> T;
while ( T-- ) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3852kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
3 1 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
5 1 1 2 3
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
5 2 1 2 3 2 3 4
output:
8
result:
ok 1 number(s): "8"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
10 1 1 2 3
output:
11
result:
ok 1 number(s): "11"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
10 1 1 2 2
output:
11
result:
ok 1 number(s): "11"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3600kb
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: 3508kb
input:
10 2 1 2 2 2 3 4
output:
14
result:
ok 1 number(s): "14"
Test #15:
score: -100
Wrong Answer
time: 0ms
memory: 3792kb
input:
10 3 1 2 3 1 8 8 2 3 3
output:
15
result:
wrong answer 1st numbers differ - expected: '13', found: '15'