Task: | Internet connection |
Sender: | Pohjantahti |
Submission time: | 2018-09-15 13:15:41 +0300 |
Language: | C++ |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.01 s | details |
#2 | ACCEPTED | 0.02 s | details |
#3 | ACCEPTED | 0.02 s | details |
#4 | ACCEPTED | 0.02 s | details |
#5 | ACCEPTED | 0.01 s | details |
#6 | ACCEPTED | 0.02 s | details |
#7 | ACCEPTED | 0.02 s | details |
#8 | ACCEPTED | 0.02 s | details |
#9 | ACCEPTED | 0.03 s | details |
#10 | ACCEPTED | 0.01 s | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:57:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (int i = 0; i < cp.size()-1; ++i) { ~~^~~~~~~~~~~~~
Code
#include <iostream> #include <algorithm> #include <vector> using namespace std; typedef long long ll; const int N = 105; const ll LINF = 1000000000000000005; int n, m; vector<int> g[N]; ll d[N][N]; int v[N]; vector<int> cp; ll res = 0; ll dfs(int s, int t, ll thr, int cvis, ll cmin) { if (v[s] == cvis) return -1; v[s] = cvis; cp.push_back(s); if (s == t) return cmin; for (int a : g[s]) { if (d[s][a] < thr) continue; ll cres = dfs(a, t, thr, cvis, min(cmin, d[s][a])); if (cres != -1) return cres; } cp.pop_back(); return -1; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; ll cthr = 0; for (int i = 0; i < m; ++i) { int a, b; ll c; cin >> a >> b >> c; g[a].push_back(b); g[b].push_back(a); d[a][b] += c; d[b][a] = 0; cthr += c; } int cvis = 0; while (true) { cvis++; cp.clear(); ll minw = dfs(1, n, cthr, cvis, LINF); if (minw != -1) { res += minw; for (int i = 0; i < cp.size()-1; ++i) { d[cp[i]][cp[i+1]] -= minw; d[cp[i+1]][cp[i]] += minw; } } else { if (cthr == 1) break; cthr /= 2; } } cout << res << "\n"; 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: ACCEPTED
input |
---|
100 1000 63 85 864540192 22 91 974117435 64 66 953124912 85 88 6080960 ... |
correct output |
---|
4397669179 |
user output |
---|
4397669179 |
Test 7
Verdict: ACCEPTED
input |
---|
100 1000 36 93 760720873 12 75 175717522 78 79 340128710 80 83 181753465 ... |
correct output |
---|
5298558023 |
user output |
---|
5298558023 |
Test 8
Verdict: ACCEPTED
input |
---|
100 1000 20 60 909693891 55 91 570199535 21 41 118646902 37 82 824735480 ... |
correct output |
---|
5466229311 |
user output |
---|
5466229311 |
Test 9
Verdict: ACCEPTED
input |
---|
100 1000 26 44 753330451 62 67 821574279 70 95 219303983 7 44 980013084 ... |
correct output |
---|
4893925638 |
user output |
---|
4893925638 |
Test 10
Verdict: ACCEPTED
input |
---|
100 1000 15 89 501388091 50 71 396801720 15 92 324349822 29 85 184420157 ... |
correct output |
---|
6956499595 |
user output |
---|
6956499595 |