Task: | 3SUM |
Sender: | odanobunaga8199 |
Submission time: | 2024-10-21 17:20:54 +0300 |
Language: | C++ (C++20) |
Status: | READY |
Result: | TIME LIMIT EXCEEDED |
test | verdict | time | |
---|---|---|---|
#1 | TIME LIMIT EXCEEDED | -- | details |
#2 | TIME LIMIT EXCEEDED | -- | details |
#3 | TIME LIMIT EXCEEDED | -- | details |
#4 | WRONG ANSWER | 0.00 s | details |
#5 | WRONG ANSWER | 0.00 s | details |
#6 | WRONG ANSWER | 0.00 s | details |
#7 | WRONG ANSWER | 0.00 s | details |
#8 | WRONG ANSWER | 0.00 s | details |
#9 | WRONG ANSWER | 0.00 s | details |
#10 | WRONG ANSWER | 0.01 s | details |
#11 | WRONG ANSWER | 0.00 s | details |
#12 | RUNTIME ERROR | 0.00 s | details |
#13 | RUNTIME ERROR | 0.00 s | details |
#14 | RUNTIME ERROR | 0.00 s | details |
#15 | RUNTIME ERROR | 0.00 s | details |
#16 | RUNTIME ERROR | 0.00 s | details |
#17 | RUNTIME ERROR | 0.00 s | details |
#18 | WRONG ANSWER | 0.00 s | details |
#19 | TIME LIMIT EXCEEDED | -- | details |
#20 | RUNTIME ERROR | 0.00 s | details |
#21 | RUNTIME ERROR | 0.00 s | details |
#22 | RUNTIME ERROR | 0.00 s | details |
#23 | WRONG ANSWER | 0.00 s | details |
Compiler report
input/code.cpp: In member function 'int MaxFlow::dfs(int, int, int)': input/code.cpp:46:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 46 | for(int &cid = ptr[v]; cid < graph[v].size(); cid++) { | ~~~~^~~~~~~~~~~~~~~~~ input/code.cpp: In function 'int main()': input/code.cpp:123:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 123 | for(int i=0; i<path.size(); i++){ | ~^~~~~~~~~~~~ input/code.cpp:124:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 124 | cout << path[i] << (i < path.size()-1 ? ' ' : '\n'); | ~~^~~~~~~~~~~~~~~
Code
#include <bits/stdc++.h> using namespace std; struct Edge { int to; int rev; int cap; }; class MaxFlow { public: int n; vector<vector<Edge>> graph; vector<int> level; vector<int> ptr; MaxFlow(int nodes) : n(nodes), graph(nodes + 1), level(nodes + 1, -1), ptr(nodes + 1, 0) {} void add_edge(int from, int to, int cap) { Edge a = {to, (int)graph[to].size(), cap}; Edge b = {from, (int)(graph[from].size()), 0}; graph[from].push_back(a); graph[to].push_back(b); } bool bfs(int s, int t) { fill(level.begin(), level.end(), -1); queue<int> q; q.push(s); level[s] = 0; while(!q.empty()) { int v = q.front(); q.pop(); for(auto &e : graph[v]) { if(e.cap > 0 && level[e.to] == -1) { level[e.to] = level[v] + 1; q.push(e.to); if(e.to == t) break; } } } return level[t] != -1; } int dfs(int v, int t, int pushed) { if(v == t) return pushed; for(int &cid = ptr[v]; cid < graph[v].size(); cid++) { Edge &e = graph[v][cid]; if(e.cap > 0 && level[e.to] == level[v] + 1) { int tr = dfs(e.to, t, min(pushed, e.cap)); if(tr > 0) { graph[e.to][e.rev].cap += tr; return tr; } } } return 0; } int max_flow_func(int s, int t) { int flow = 0; while(bfs(s, t)) { fill(ptr.begin(), ptr.end(), 0); while(int pushed = dfs(s, t, INT32_MAX)) { flow += pushed; } } return flow; } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; MaxFlow mf(n); for(int i=0; i<m; i++){ int a, b; cin >> a >> b; mf.add_edge(a, b, 1); } int max_flow = mf.max_flow_func(1, n); vector<vector<int>> paths; vector<vector<Edge>> residual_graph = mf.graph; function<bool(int, int, vector<int>&, vector<vector<Edge>> &)> find_path = [&](int u, int t, vector<int> &path, vector<vector<Edge>> &res_g) -> bool { if(u == t){ return true; } for(auto &e : res_g[u]){ if(e.cap == 0) { e.cap = -1; auto &rev_edge = res_g[e.to][e.rev]; rev_edge.cap = -1; path.push_back(e.to); if(find_path(e.to, t, path, res_g)){ return true; } path.pop_back(); e.cap = 0; rev_edge.cap = 0; } } return false; }; for(int i=0; i<max_flow; i++){ vector<int> path; path.push_back(1); bool found = find_path(1, n, path, residual_graph); if(found){ paths.push_back(path); } } cout << max_flow << "\n"; for(auto &path : paths){ cout << path.size() << "\n"; for(int i=0; i<path.size(); i++){ cout << path[i] << (i < path.size()-1 ? ' ' : '\n'); } } }
Test details
Test 1
Verdict: TIME LIMIT EXCEEDED
input |
---|
1 3 1 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
(empty) |
Test 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
3 5 1 3 2 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
(empty) |
Test 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
3 6 1 3 2 |
correct output |
---|
1 3 2 |
user output |
---|
(empty) |
Test 4
Verdict: WRONG ANSWER
input |
---|
3 7 3 2 1 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
0 |
Test 5
Verdict: WRONG ANSWER
input |
---|
7 3 2 1 1 2 2 1 1 |
correct output |
---|
2 3 7 |
user output |
---|
0 |
Test 6
Verdict: WRONG ANSWER
input |
---|
7 4 1 1 2 2 1 2 1 |
correct output |
---|
1 2 6 |
user output |
---|
0 |
Test 7
Verdict: WRONG ANSWER
input |
---|
7 5 1 2 1 2 2 1 1 |
correct output |
---|
1 2 5 |
user output |
---|
0 |
Test 8
Verdict: WRONG ANSWER
input |
---|
7 6 2 1 1 1 1 2 2 |
correct output |
---|
1 6 7 |
user output |
---|
0 |
Test 9
Verdict: WRONG ANSWER
input |
---|
5000 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
correct output |
---|
1 2 5000 |
user output |
---|
0 |
Test 10
Verdict: WRONG ANSWER
input |
---|
5000 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
0 |
Test 11
Verdict: WRONG ANSWER
input |
---|
5000 6 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
correct output |
---|
714 3518 4240 |
user output |
---|
0 |
Test 12
Verdict: RUNTIME ERROR
input |
---|
5000 919900245 663612758 9075403 585385629 98... |
correct output |
---|
2787 465 2266 |
user output |
---|
(empty) |
Test 13
Verdict: RUNTIME ERROR
input |
---|
5000 999989608 12983 25966 38949 51932 64915 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
(empty) |
Test 14
Verdict: RUNTIME ERROR
input |
---|
5000 1000000000 65536 131072 196608 262144 327... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
(empty) |
Test 15
Verdict: RUNTIME ERROR
input |
---|
5000 642700000 6427 12854 19281 25708 32135 3... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
(empty) |
Test 16
Verdict: RUNTIME ERROR
input |
---|
5000 919900246 663612758 9075403 585385629 98... |
correct output |
---|
193 1698 4019 |
user output |
---|
(empty) |
Test 17
Verdict: RUNTIME ERROR
input |
---|
5000 919900247 663612758 9075403 585385629 98... |
correct output |
---|
4258 470 1911 |
user output |
---|
(empty) |
Test 18
Verdict: WRONG ANSWER
input |
---|
5000 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 ... |
correct output |
---|
4998 4999 5000 |
user output |
---|
0 |
Test 19
Verdict: TIME LIMIT EXCEEDED
input |
---|
5000 919900247 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
(empty) |
Test 20
Verdict: RUNTIME ERROR
input |
---|
4999 919900245 9075403 585385629 987230075 83... |
correct output |
---|
2786 464 2265 |
user output |
---|
(empty) |
Test 21
Verdict: RUNTIME ERROR
input |
---|
5000 1000000000 261323261 25262018 237798562 3... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
(empty) |
Test 22
Verdict: RUNTIME ERROR
input |
---|
5000 76305003 1 5088 10175 15262 20349 25436... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
(empty) |
Test 23
Verdict: WRONG ANSWER
input |
---|
2 6 2 2 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
0 |