Task: | Internet connection |
Sender: | niketin |
Submission time: | 2020-09-19 15:18:52 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.01 s | details |
#2 | ACCEPTED | 0.01 s | details |
#3 | ACCEPTED | 0.01 s | details |
#4 | ACCEPTED | 0.01 s | details |
#5 | ACCEPTED | 0.01 s | details |
#6 | WRONG ANSWER | 0.01 s | details |
#7 | WRONG ANSWER | 0.01 s | details |
#8 | WRONG ANSWER | 0.01 s | details |
#9 | WRONG ANSWER | 0.01 s | details |
#10 | WRONG ANSWER | 0.01 s | details |
#11 | ACCEPTED | 0.01 s | details |
#12 | ACCEPTED | 0.01 s | details |
#13 | ACCEPTED | 0.01 s | details |
#14 | ACCEPTED | 0.01 s | details |
#15 | ACCEPTED | 0.01 s | details |
#16 | ACCEPTED | 0.01 s | details |
#17 | ACCEPTED | 0.01 s | details |
#18 | WRONG ANSWER | 0.01 s | details |
#19 | ACCEPTED | 0.01 s | details |
#20 | ACCEPTED | 0.01 s | details |
#21 | ACCEPTED | 0.01 s | details |
#22 | ACCEPTED | 0.01 s | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:73:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (int v = 0; v < g[u].size(); v++) { ~~^~~~~~~~~~~~~
Code
#include <iostream> #include <algorithm> #include <string> #include <bits/stdc++.h> #define N 1000 using namespace std; vector<int> g[N]; map<pair<int, int>, int> weights; map<pair<int, int>, int> flow; vector<pair<int, int>> bfs(int s, int t) { queue<int> q; vector<bool> vis(N); map<int, vector<int>> mm; q.push(s); while( not q.empty()) { auto u = q.front(); q.pop(); if (u == t) { vector<pair<int, int>> res; while (true) { if (u == s) { reverse(res.begin(), res.end()); return res; } int v = mm[u].front(); res.push_back(make_pair(v, u)); u = v; } } if (not vis[u]) { vis[u] = true; for(auto &v: g[u]) { if (weights[make_pair(u, v)] - flow[make_pair(u, v)] > 0 and not vis[v]) { q.push(v); if (mm.find(v) == mm.end()) { vector<int> xxx = {u}; mm[v] = xxx; }else { mm[v].push_back(u); } } } } } return vector<pair<int, int>>(); } int main() { int n, m; // n vertices, m edges // build up the cin >> n >> m; for (int i = 0; i < m; i++) { int v, w, c; cin >> v >> w >> c; g[v].push_back(w); //g[w].push_back(v); weights[make_pair(v, w)] = c; } for (int u = 0; u < n; u++) { for (int v = 0; v < g[u].size(); v++) { if (g[u][v] == 0) { break; } flow[make_pair(u, v)] = 0; flow[make_pair(v, u)] = 0; } } while (true) { auto v = bfs(1, n); if (v.empty()) { break; } auto smallestpair = *min_element(v.begin(), v.end(), [&](const pair<int, int> &a, const pair<int, int> &b){ return weights[a] - flow[a] < weights[b] - flow[b];}); auto cfp = weights[smallestpair] - flow[smallestpair]; for (auto &i : v) { auto u = i.first; auto v = i.second; flow[make_pair(u, v)] = flow[make_pair(u, v)] + cfp; flow[make_pair(v, u)] = flow[make_pair(v, u)] - cfp; } } int s = 0; for (auto & gg: g[1]) { s += flow[make_pair(1, gg)]; } cout << s; return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
10 20 5 6 19 4 5 47 3 5 7 4 9 62 ... |
correct output |
---|
73 |
user output |
---|
73 |
Test 2
Verdict: ACCEPTED
input |
---|
10 20 2 4 63 7 9 54 6 7 16 2 3 9 ... |
correct output |
---|
110 |
user output |
---|
110 |
Test 3
Verdict: ACCEPTED
input |
---|
10 20 5 6 90 2 3 46 7 8 80 6 7 60 ... |
correct output |
---|
29 |
user output |
---|
29 |
Test 4
Verdict: ACCEPTED
input |
---|
10 20 3 4 76 5 7 8 3 8 71 4 7 24 ... |
correct output |
---|
95 |
user output |
---|
95 |
Test 5
Verdict: ACCEPTED
input |
---|
10 20 1 8 22 6 7 40 4 5 20 8 10 77 ... |
correct output |
---|
156 |
user output |
---|
156 |
Test 6
Verdict: WRONG ANSWER
input |
---|
100 1000 63 85 864540192 22 91 974117435 64 66 953124912 85 88 6080960 ... |
correct output |
---|
4397669179 |
user output |
---|
102701883 |
Test 7
Verdict: WRONG ANSWER
input |
---|
100 1000 36 93 760720873 12 75 175717522 78 79 340128710 80 83 181753465 ... |
correct output |
---|
5298558023 |
user output |
---|
634571070 |
Test 8
Verdict: WRONG ANSWER
input |
---|
100 1000 20 60 909693891 55 91 570199535 21 41 118646902 37 82 824735480 ... |
correct output |
---|
5466229311 |
user output |
---|
1171262015 |
Test 9
Verdict: WRONG ANSWER
input |
---|
100 1000 26 44 753330451 62 67 821574279 70 95 219303983 7 44 980013084 ... |
correct output |
---|
4893925638 |
user output |
---|
598958342 |
Test 10
Verdict: WRONG ANSWER
input |
---|
100 1000 15 89 501388091 50 71 396801720 15 92 324349822 29 85 184420157 ... |
correct output |
---|
6956499595 |
user output |
---|
-1633434997 |
Test 11
Verdict: ACCEPTED
input |
---|
2 1 1 2 1 |
correct output |
---|
1 |
user output |
---|
1 |
Test 12
Verdict: ACCEPTED
input |
---|
2 1 2 1 1 |
correct output |
---|
0 |
user output |
---|
0 |
Test 13
Verdict: ACCEPTED
input |
---|
2 2 1 2 1 2 1 1 |
correct output |
---|
1 |
user output |
---|
1 |
Test 14
Verdict: ACCEPTED
input |
---|
100 1000 1 2 539540023 2 3 244306651 3 4 253259012 3 5 630461598 ... |
correct output |
---|
0 |
user output |
---|
0 |
Test 15
Verdict: ACCEPTED
input |
---|
4 5 1 2 2 1 3 5 2 4 3 3 2 2 ... |
correct output |
---|
4 |
user output |
---|
4 |
Test 16
Verdict: ACCEPTED
input |
---|
2 0 |
correct output |
---|
0 |
user output |
---|
0 |
Test 17
Verdict: ACCEPTED
input |
---|
100 0 |
correct output |
---|
0 |
user output |
---|
0 |
Test 18
Verdict: WRONG ANSWER
input |
---|
100 196 1 2 1000000000 2 100 1000000000 1 3 1000000000 3 100 1000000000 ... |
correct output |
---|
98000000000 |
user output |
---|
-784247808 |
Test 19
Verdict: ACCEPTED
input |
---|
100 99 1 2 1000000000 2 3 1000000000 3 4 1000000000 4 5 1000000000 ... |
correct output |
---|
1000000000 |
user output |
---|
1000000000 |
Test 20
Verdict: ACCEPTED
input |
---|
2 2 2 1 1 1 2 1 |
correct output |
---|
1 |
user output |
---|
1 |
Test 21
Verdict: ACCEPTED
input |
---|
4 6 1 2 1000000000 1 3 1000000000 2 3 1 2 4 1000000000 ... |
correct output |
---|
2000000000 |
user output |
---|
2000000000 |
Test 22
Verdict: ACCEPTED
input |
---|
4 6 1 2 1000000000 1 3 1000000000 2 4 1000000000 2 3 1 ... |
correct output |
---|
2000000000 |
user output |
---|
2000000000 |