QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#604658 | #8760. 不等式 | xing4c# | WA | 5ms | 12876kb | C++14 | 1.3kb | 2024-10-02 12:53:55 | 2024-10-02 12:53:55 |
Judging History
answer
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
const int N = 2e5 + 7;
#define int long long
vector<pair<int, int>> G[N];
int in[N] = {0};
int vis[N] = {0};
int w[N] = {0};
void solve() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int x, y, z;
cin >> x >> y >> z;
G[y].push_back({x, z});
G[z].push_back({x, y});
in[x] += 2;
}
queue<int> Q;
for (int i = 1; i <= n; i++) {
if (in[i] == 0) {
Q.push(i);
w[i] = 1;
}
}
while (!Q.empty()) {
int u = Q.front();
vis[u] = 1;
Q.pop();
for (auto [to, fri]: G[u]) {
if (w[fri]) {
w[to] = max(w[to], w[u] + w[fri]);
in[to]--;
if (in[to] == 0)Q.push(to);
}
}
}
int sum = 0;
for (int i = 1; i <= n; i++) {
sum += w[i];
if (w[i] == 0) {
cout << -1 << endl;
return;
}
}
cout << sum << endl;
}
signed main() {
// freopen("D:\\Development_Software\\CLion\\CLionProjects\\Test\\in", "r", stdin);
ios::sync_with_stdio(false);
int T = 1;
while (T--)solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 11328kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 3ms
memory: 12160kb
input:
3 1 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 11288kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: 0
Accepted
time: 0ms
memory: 12260kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #5:
score: 0
Accepted
time: 2ms
memory: 11452kb
input:
3 1 1 2 2
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 0ms
memory: 11364kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #7:
score: 0
Accepted
time: 0ms
memory: 11156kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 5ms
memory: 12260kb
input:
5 1 1 2 2
output:
6
result:
ok 1 number(s): "6"
Test #9:
score: 0
Accepted
time: 0ms
memory: 12640kb
input:
5 1 1 2 3
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 0ms
memory: 12876kb
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: 11524kb
input:
10 1 1 2 3
output:
11
result:
ok 1 number(s): "11"
Test #12:
score: 0
Accepted
time: 4ms
memory: 11220kb
input:
10 1 1 2 2
output:
11
result:
ok 1 number(s): "11"
Test #13:
score: 0
Accepted
time: 0ms
memory: 11084kb
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: 11136kb
input:
10 2 1 2 2 2 3 4
output:
14
result:
ok 1 number(s): "14"
Test #15:
score: 0
Accepted
time: 3ms
memory: 12536kb
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: 4ms
memory: 12680kb
input:
20 1 1 2 2
output:
21
result:
ok 1 number(s): "21"
Test #17:
score: 0
Accepted
time: 0ms
memory: 10960kb
input:
20 2 1 2 3 2 3 3
output:
23
result:
ok 1 number(s): "23"
Test #18:
score: 0
Accepted
time: 0ms
memory: 11704kb
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: 3ms
memory: 11264kb
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: 3ms
memory: 10940kb
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'