QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#638372#8760. 不等式ricofx#WA 4ms16072kbC++201.9kb2024-10-13 15:45:522024-10-13 15:45:53

Judging History

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

  • [2024-10-13 15:45:53]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:16072kb
  • [2024-10-13 15:45:52]
  • 提交

answer

//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 998244353;
const int N = 2e5 + 5;

int n, m;
vector<int> G[N];
int in[N], vis[N];
ll dp[N];
map<int, int> mp[N];
void MAIN() {
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int a, b, c;
        cin >> c >> b >> a;
        G[a].push_back(c);
        G[b].push_back(c);
        in[c]++;
        in[c]++;
        if (a == b) mp[c][a] = -1;
    }
    queue<int> q;
    for (int i = 1; i <= n; i++) {
        if (!in[i]) q.push(i), dp[i] = 1;
    }
    while (!q.empty()) {
        int u = q.front(); q.pop();
        vis[u] = 1;
        for (int v : G[u]) {
            if (!mp[v].count(u) || mp[v][u] == -1) {
                if (mp[v][u] == -1) dp[v] += dp[u];
                mp[v][u] = 1;
                dp[v] += dp[u];
            }
            if (dp[v] > 1000000000ll) cout << -1 << '\n';
            --in[v];
            if (!in[v]) q.push(v);
        }
    }
    ll sum = 0;
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) return cout << "-1\n", void();
        sum += dp[i];
    }
    if (sum > 1000000000ll) cout << -1 << '\n';
    else cout << sum << '\n';
}

int main() {
#ifdef LOCAL
    auto start = chrono::steady_clock::now();
    freopen("miku.in", "r", stdin);
    freopen("miku.out", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    // cin >> T;
    while (T--) MAIN();
#ifdef LOCAL
    auto end = chrono::steady_clock::now();
    cout << "\nqwq: " <<  chrono::duration_cast<chrono::milliseconds>(end - start).count() << "ms\n";
#endif
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 14748kb

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 4ms
memory: 16072kb

input:

3 1
1 2 3

output:

4

result:

ok 1 number(s): "4"

Test #3:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #4:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #5:

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

input:

3 1
1 2 2

output:

4

result:

ok 1 number(s): "4"

Test #6:

score: 0
Accepted
time: 4ms
memory: 15716kb

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #7:

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

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #8:

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

input:

5 1
1 2 2

output:

6

result:

ok 1 number(s): "6"

Test #9:

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

input:

5 1
1 2 3

output:

6

result:

ok 1 number(s): "6"

Test #10:

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

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

input:

10 1
1 2 3

output:

11

result:

ok 1 number(s): "11"

Test #12:

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

input:

10 1
1 2 2

output:

11

result:

ok 1 number(s): "11"

Test #13:

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

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

input:

10 2
1 2 2
2 3 4

output:

14

result:

ok 1 number(s): "14"

Test #15:

score: -100
Wrong Answer
time: 2ms
memory: 14676kb

input:

10 3
1 2 3
1 8 8
2 3 3

output:

15

result:

wrong answer 1st numbers differ - expected: '13', found: '15'