QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#776601#8760. 不等式WilliamFungWA 3ms10064kbC++113.1kb2024-11-23 19:38:242024-11-23 19:38:25

Judging History

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

  • [2024-11-23 19:38:25]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:10064kb
  • [2024-11-23 19:38:24]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n'
#define all(a) a.begin(), a.end()
#define ll long long
#define ull unsigned long long
#define inf 0x7fffffff;
//#define int long long
//#define III int
using namespace std;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<vector<int>>;
using vll = vector<vector<ll>>;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
//cout << ceil(-0.2) << endl;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const ll INF = 1e18;

// struct node {
//     ll dis, u;
//     int hh;
//     bool operator>(const node &a) const {return dis > a.dis;}
// };

struct now {
    ll a, b;
    bool operator<(const now& x) const {
        return a < x.a;
    }
};

ll qpow (ll a, ll b) {
    ll ret = 1;
    a %= mod;
    while (b) {
        if (b & 1) {
            ret *= a;
            ret %= mod;
        }
        b /= 2;
        a = (a * a) % mod;
    }
    return ret;
}

ll cmp (ll a, ll b) {
    if (a == 0) return 0;
    if (a > b / 2) a = b - a;
    ll x = 1, y = 1;
    for (int i = 0; i < a; i++) {
        x *= b - i;
        x %= mod;
    }
    for (int i = 1; i <= a; i++) {
        y *= i;
        y %= mod;
    }
    ll ret = x * qpow(y, mod - 2);
    ret %= mod;
    return ret;
}
int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

struct node {
    ll w, l, r;
};

// //int n;
// ll tree[500005];
// int lowbit(int x) {
//     return x & (-x);
// }
// void add(int l, ll x) {
//     for (int i = l; i <= n; i += lowbit(i)) {
//         tree[i] += x;
//     }
// }
// ll sum(int r) {
//     ll ret = 0;
//     for (int i = r; i >= 1; i -= lowbit(i)) {
//         ret += tree[i];
//     }
//     return ret;
// }

int n, m;
ll in[200010];
vector<pair<int, int>> g[200010];
void solve() {
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        g[b].emplace_back(a, c);
        if (c != b) g[c].emplace_back(a, b);
        in[a]++;
    }
    queue<int> q;
    vector<ll> ans(n + 1);
    vector<int> flag(n + 1);
    for (int i = 1; i <= n; i++) {
        if (in[i] == 0) {
            q.push(i);
            ans[i] = 1;
            flag[i] = 1;
        }
    }
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (auto p : g[u]) {
            if (flag[p.first]) continue;
            if (flag[p.second]) {
                ans[p.first] = max(ans[p.first], ans[u] + ans[p.second]);
                in[p.first]--;
                if (in[p.first] == 0) {
                    q.push(p.first);
                    flag[p.first] = 1;
                }
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        if (flag[i] == 0) {
            cout << -1 << endl;
            return;
        }
    }
    ll sum = 0;
    for (int i = 1; i <= n; i++) {
        sum += ans[i];
    }
    cout << sum << endl;
}



int main() {
    std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr);
    // helper();
    int t = 1;
    //cin >> t;
    while (t--) solve();




    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 8532kb

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 9196kb

input:

3 1
1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #3:

score: 0
Accepted
time: 3ms
memory: 9324kb

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #4:

score: 0
Accepted
time: 0ms
memory: 8232kb

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #5:

score: 0
Accepted
time: 2ms
memory: 8700kb

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #6:

score: 0
Accepted
time: 0ms
memory: 10064kb

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #7:

score: 0
Accepted
time: 0ms
memory: 9264kb

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #8:

score: 0
Accepted
time: 0ms
memory: 9472kb

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #9:

score: 0
Accepted
time: 0ms
memory: 8292kb

input:

5 1
1 2 3

output:

6

result:

ok 1 number(s): "6"

Test #10:

score: 0
Accepted
time: 0ms
memory: 9392kb

input:

5 2
1 2 3
2 3 4

output:

8

result:

ok 1 number(s): "8"

Test #11:

score: 0
Accepted
time: 3ms
memory: 9460kb

input:

10 1
1 2 3

output:

11

result:

ok 1 number(s): "11"

Test #12:

score: 0
Accepted
time: 0ms
memory: 9556kb

input:

10 1
1 2 2

output:

11

result:

ok 1 number(s): "11"

Test #13:

score: 0
Accepted
time: 3ms
memory: 9728kb

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: 9676kb

input:

10 2
1 2 2
2 3 4

output:

14

result:

ok 1 number(s): "14"

Test #15:

score: 0
Accepted
time: 0ms
memory: 8744kb

input:

10 3
1 2 3
1 8 8
2 3 3

output:

13

result:

ok 1 number(s): "13"

Test #16:

score: 0
Accepted
time: 0ms
memory: 8724kb

input:

20 1
1 2 2

output:

21

result:

ok 1 number(s): "21"

Test #17:

score: 0
Accepted
time: 3ms
memory: 9832kb

input:

20 2
1 2 3
2 3 3

output:

23

result:

ok 1 number(s): "23"

Test #18:

score: 0
Accepted
time: 2ms
memory: 8484kb

input:

20 3
7 14 6
1 2 3
4 7 20

output:

24

result:

ok 1 number(s): "24"

Test #19:

score: 0
Accepted
time: 2ms
memory: 8692kb

input:

20 4
1 2 2
6 10 6
2 3 3
3 4 5

output:

-1

result:

ok 1 number(s): "-1"

Test #20:

score: -100
Wrong Answer
time: 0ms
memory: 8772kb

input:

20 5
1 17 3
1 2 3
2 3 4
3 4 5
8 13 16

output:

26

result:

wrong answer 1st numbers differ - expected: '28', found: '26'