# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
253837 |
2020-07-28T21:35:43 Z |
aZvezda |
Pipes (BOI13_pipes) |
C++14 |
|
0 ms |
0 KB |
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl
const int MAX_N = 1e5 + 10;
set<pair<int, int> > g[MAX_N];
int ans[MAX_N], arr[MAX_N];
struct cmp {
bool operator ()(const int &a, const int &b) const {
if(g[a].size() == g[b].size()) {
return a < b;
}
return g[a].size() < g[b].size();
}
};
multiset<int, cmp> pq;
void removeBranches() {
while(!pq.empty() && g[*(pq.begin())].size() == 1) {
int curr = *(pq.begin()); pq.erase(pq.begin());
auto other = *(g[curr].begin());
ans[other.second] = arr[curr];
arr[other.first] -= arr[curr];
g[other.first].erase({curr, other.second});
}
}
signed main() {
//ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int n, m;
cin >> n >> m;
if(m > n) {cout << 0 << endl; return 0;}
for(int i = 1; i <= n; i ++) {
cin >> arr[i];
}
for(int i = 0; i < m; i ++) {
int a, b;
cin >> a >> b;
g[a].insert({b, i});
g[b].insert({a, i});
}
for(int i = 1; i <= n; i ++) {
pq.insert(i);
}
removeBranches();
for(int i = 0; i < м; i ++) {
cout << ans[i] * 2 << endl;
}
return 0;
}
Compilation message
pipes.cpp:58:24: error: stray '\320' in program
for(int i = 0; i < м; i ++) {
^
pipes.cpp:58:25: error: stray '\274' in program
for(int i = 0; i < м; i ++) {
^
pipes.cpp: In function 'int main()':
pipes.cpp:58:26: error: expected primary-expression before ';' token
for(int i = 0; i < м; i ++) {
^