QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#604494 | #8760. 不等式 | ITC_TL# | WA | 2ms | 13816kb | C++20 | 1.6kb | 2024-10-02 11:22:59 | 2024-10-02 11:22:59 |
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);
}
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])
{
if (vis[to[i]])
continue;
vis[to[i]] = 1;
val[to[i]] += val[t];
deg[to[i]]--;
sum1--;
if (deg[to[i]] == 0)
{
q.push(to[i]);
}
}
for (register int i = hand[t]; i; i = nxt[i])
{
vis[to[i]] = 0;
}
}
if (!p || sum1 != 0)
{
cout << -1 << endl;
}
else
{
cout << ans << endl;
}
return 0;
}
/*
7 3
1 2 3
2 4 5
3 6 7
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 13816kb
input:
3 1 1 2 2
output:
-1
result:
wrong answer 1st numbers differ - expected: '4', found: '-1'