QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#604375 | #8760. 不等式 | ITC_TL# | WA | 3ms | 14108kb | C++20 | 1.5kb | 2024-10-02 10:28:06 | 2024-10-02 10:28:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fore(i, l, r) for (register int i = (int)l; i <= (int)r; i++)
#define ford(i, r, l) for (register int i = (int)r; i >= (int)l; i--)
const int MAXN = 2123456LL;
ll T, n, a[MAXN];
ll tot, hand[MAXN], nxt[MAXN], to[MAXN];
ll fa[MAXN], m, deg[MAXN], val[MAXN], sum1;
bool vis[MAXN];
queue<ll> q;
void add(ll x, ll y)
{
tot++;
to[tot] = y;
nxt[tot] = hand[x];
hand[x] = tot;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
ll l, r1, r2;
bool p = 1;
fore(i, 1, m)
{
cin >> l >> r1 >> r2;
add(r1, l);
add(r2, l);
deg[l] += 2;
sum1 += 2;
}
ll ans = 0;
fore(i, 1, n)
{
if (deg[i] == 0)
val[i] = 1, q.push(i), vis[i] = 1;
}
while (!q.empty())
{
ll t = q.front();
q.pop();
ans += val[t];
if (ans > 1e9)
{
p = 0;
break;
}
for (register int i = hand[t]; i; i = nxt[i])
{
val[to[i]] += val[t];
deg[to[i]]--;
sum1--;
if (deg[to[i]] == 0)
{
q.push(to[i]);
}
}
}
if (!p || sum1 != 0)
{
cout << -1 << endl;
}
else
{
cout << ans << endl;
}
return 0;
}
/*
5 2
1 2 3
3 4 5
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 13760kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 14108kb
input:
3 1 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 13816kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: 0
Accepted
time: 0ms
memory: 14104kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #5:
score: 0
Accepted
time: 0ms
memory: 13880kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 3ms
memory: 14068kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #7:
score: 0
Accepted
time: 3ms
memory: 14068kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 0ms
memory: 13820kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #9:
score: 0
Accepted
time: 0ms
memory: 13848kb
input:
5 1 1 2 3
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 0ms
memory: 13812kb
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: 13816kb
input:
10 1 1 2 3
output:
11
result:
ok 1 number(s): "11"
Test #12:
score: 0
Accepted
time: 0ms
memory: 13756kb
input:
10 1 1 2 2
output:
11
result:
ok 1 number(s): "11"
Test #13:
score: 0
Accepted
time: 0ms
memory: 13816kb
input:
10 2 1 2 3 2 3 4
output:
13
result:
ok 1 number(s): "13"
Test #14:
score: 0
Accepted
time: 3ms
memory: 14072kb
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: 13852kb
input:
10 3 1 2 3 1 8 8 2 3 3
output:
15
result:
wrong answer 1st numbers differ - expected: '13', found: '15'