QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#604497#8760. 不等式ITC_TL#WA 0ms13804kbC++201.6kb2024-10-02 11:24:222024-10-02 11:24:24

Judging History

你现在查看的是最新测评结果

  • [2024-10-02 11:24:24]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:13804kb
  • [2024-10-02 11:24:22]
  • 提交

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]])
                val[to[i]] += val[t];
            vis[to[i]] = 1;
            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: 0ms
memory: 13804kb

input:

3 1
1 2 2

output:

3

result:

wrong answer 1st numbers differ - expected: '4', found: '3'