Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

typedef pair<int, int> P;

struct edge{ int to; vector<int> cap; int rev; };

const int MAX_V = 50;
const int INF = 1 << 28;
const int L = 52;

vector<edge> G[MAX_V];
bool used[MAX_V];
vector<int> vec_zero(L, 0);

void add_edge(int from, int to, vector<int> cap){
  G[from].push_back((edge){to, cap, G[to].size()});
  G[to].push_back((edge){from, vec_zero, G[from].size() - 1});
}

vector<int> dfs(int v, int t, vector<int> f){
  if(v == t) return f;
  used[v] = true;
  for(int i=0;i<G[v].size();i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > vec_zero){
      vector<int> d = dfs(e.to, t, min(f, e.cap));
      if(d > vec_zero){
				bool zero = false;
        //e.cap -= d;
        for(int j=0;j<L;j++){
					if(e.cap[j] - d[j] <= 0){
						zero = true;
					}
					if(zero) e.cap[j] = 0;
					else{
						e.cap[j] -= d[j];
					}

        }
        //G[e.to][e.rev].cap += d;
        for(int j=0;j<L;j++){
          G[e.to][e.rev].cap[j] += d[j];
        }
        return d;
      }
    }
  }
  return vec_zero;
}

vector<int> max_flow(int s, int t){
  vector<int> vec_INF = vec_zero;
  vec_INF[0] = 1;
  vector<int> flow = vec_zero;
  for(;;){
    memset(used, 0, sizeof(used));
    vector<int> f = dfs(s, t, vec_INF);
/*
		for(int j=0;j<L;j++){
			cout << f[j] << ' ';
		}
		cout << endl;
*/
    if(f == vec_zero) return flow;
/*
		cout << "*"
		for(int j=0;j<L;j++){
			cout << f[j] << ' ';
		}
		cout << endl;
*/
    //flow += f;
    for(int j=0;j<L;j++){
      flow[j] += f[j];
    }
  }
}

void init(){
  for(int i=0;i<MAX_V;i++){
    G[i].clear();
  }
}

P calc2(string s){
  int x = -1;
  for(int i=0;i<s.size();i++){
    if(s[i] == 'x'){
      x = i;
    }
  }
  if(x == -1){
    return make_pair(0, atoi(s.c_str()));
  }
  P res;
	string tmp = s.substr(0, x);
	if(tmp.size() == 0){
		res.second = 1;
	}else{
		res.second = atoi(tmp.c_str());
	}
  int h = -1;
  for(int i=0;i<s.size();i++){
    if(s[i] == '^'){
      res.first = atoi(s.substr(i+1).c_str());
    }
  }
	if(h == -1){
		res.first = 1;
	}
  return res;
}

vector<int> calc(string s){
  vector<int> res(L, 0);
  int pre = 0;
  for(int i=0;;i++){
    if(i == s.size()){
      P tmp = calc2(s.substr(pre, pre + (i - pre)));
      res[tmp.first] += tmp.second;
      break;
    }
    if(s[i] == '+'){
      P tmp = calc2(s.substr(pre, pre + (i - pre)));
      res[tmp.first] += tmp.second;
      pre = i + 1;
    }
  }
  return res;
}

int V, E;

main(){
  while(cin >> V >> E && (V|E)){
    for(int i=0;i<E;i++){
      int a, b;
      string s;
      cin >> a >> b >> s;
      a--; b--;
      //cout << i << endl;
      vector<int> tmp = calc(s);
			//for(int i=0;i<10;i++) cout << tmp[i] << ' '; cout << endl;
			reverse(tmp.begin(), tmp.end());
      add_edge(a, b, tmp);
      add_edge(b, a, tmp);
    }
    vector<int> ans = max_flow(0, V-1);
		reverse(ans.begin(), ans.end());
/*
		for(int i=0;i<ans.size();i++){
			cout << ans[i] << ' ';
		}
		cout << endl;
*/
    bool first = true;
    for(int i=L-1;i>=0;i--){
      if(ans[i] == 0) continue;
      if(first) first = false;
      else{
        cout << "+";
      }
      if(i == 0){
        cout << ans[i];
      }else{
				if(ans[i] != 1) cout << ans[i];
				if(i == 1){
					cout << "x";
				}else{
					cout << "x^" << i;
				}
      }
    }
    if(first){
      cout << 0 << endl;
    }else{
      cout << endl;
    }
  }
}

Compiler output:
a.cc: In function 'void add_edge(int, int, std::vector<int>)':
a.cc:21:47: warning: narrowing conversion of 'G[to].std::vector<edge>::size()' from 'std::vector<edge>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   21 |   G[from].push_back((edge){to, cap, G[to].size()});
      |                                     ~~~~~~~~~~^~
a.cc:22:57: warning: narrowing conversion of '(G[from].std::vector<edge>::size() - 1)' from 'std::vector<edge>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   22 |   G[to].push_back((edge){from, vec_zero, G[from].size() - 1});
      |                                          ~~~~~~~~~~~~~~~^~~
a.cc: In function 'std::vector<int> max_flow(int, int)':
a.cc:61:5: error: 'memset' was not declared in this scope
   61 |     memset(used, 0, sizeof(used));
      |     ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    4 | #include <map>
  +++ |+#include <cstring>
    5 | 
a.cc: At global scope:
a.cc:139:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  139 | main(){
      | ^~~~