QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#638316#8760. 不等式ricofx#WA 1ms3680kbC++201.7kb2024-10-13 15:37:502024-10-13 15:37:51

Judging History

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

  • [2024-10-13 15:37:51]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3680kb
  • [2024-10-13 15:37:50]
  • 提交

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];
void MAIN() {
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        G[a].push_back(c);
        G[b].push_back(c);
        in[c]++;
        in[c]++;
    }
    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]) {
           // cout << u << ' ' << v << ' '  << in[v] <<  '\n';
            dp[v] += dp[u];
            --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;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3680kb

input:

3 1
1 2 2

output:

-1

result:

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