QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#604518 | #8760. 不等式 | xing4c# | WA | 2ms | 11968kb | C++14 | 1.1kb | 2024-10-02 11:43:05 | 2024-10-02 11:43:06 |
Judging History
answer
#include <bits/stdc++.h>
#define NOSYNC ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define all(x) x.begin(), x.end()
#define endl '\n'
#define int ll
using namespace std;
using ll = long long;
using ull = unsigned long long;
const int N = 200005;
// -------------- Templates Above -------------------------
int a[N]; int n, m;
vector<int> g[N];
int d[N]; int in[N];
signed main() {
NOSYNC;
cin >> n >> m;
for(int i = 1; i <= m; i ++) {
int x, y, z;
cin >> x >> y >> z;
g[y].push_back(x);
g[z].push_back(x);
d[x] += 2;
}
queue<int> q;
for(int i = 1; i <= n; i ++) {
if(!d[i]) {
q.push(i);
in[i] = 1;
a[i] = 1;
}
}
while(!q.empty()) {
int u = q.front();
q.pop();
for(int v : g[u]) {
-- d[v];
a[v] += a[u];
if(!d[v]) {
q.push(v);
in[v] = 1;
}
}
}
ll ans = 0;
for(int i = 1; i <= n; i ++) {
if(d[i]) {
cout << -1 << endl;
return 0;
}
ans += a[i];
}
const int lim = 1e9;
if(ans > lim) {
cout << -1 << endl;
return 0;
}
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 10128kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 11964kb
input:
3 1 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 2ms
memory: 10000kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: 0
Accepted
time: 0ms
memory: 11968kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #5:
score: 0
Accepted
time: 2ms
memory: 10072kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 2ms
memory: 9800kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #7:
score: 0
Accepted
time: 0ms
memory: 9772kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 1ms
memory: 9668kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #9:
score: 0
Accepted
time: 2ms
memory: 11964kb
input:
5 1 1 2 3
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 0ms
memory: 11796kb
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: 11804kb
input:
10 1 1 2 3
output:
11
result:
ok 1 number(s): "11"
Test #12:
score: 0
Accepted
time: 2ms
memory: 11780kb
input:
10 1 1 2 2
output:
11
result:
ok 1 number(s): "11"
Test #13:
score: 0
Accepted
time: 2ms
memory: 11716kb
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: 11800kb
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: 9736kb
input:
10 3 1 2 3 1 8 8 2 3 3
output:
15
result:
wrong answer 1st numbers differ - expected: '13', found: '15'