Submission #251542

#TimeUsernameProblemLanguageResultExecution timeMemory
251542abacabaPipes (BOI13_pipes)C++14
48.15 / 100
262 ms29176 KiB
#include <iostream> #include <string> #include <unordered_map> #include <unordered_set> #include <cstring> #include <chrono> #include <vector> #include <map> #include <random> #include <set> #include <algorithm> #include <math.h> #include <cstdio> #include <stdio.h> #include <queue> #include <bitset> #include <cstdlib> #include <deque> #include <cassert> #include <stack> using namespace std; #define mp make_pair #define f first #define se second #define pb push_back #define ppb pop_back #define emb emplace_back #define ll long long #define ull unsigned long long #define cntbit(x) __builtin_popcount(x) #define endl '\n' #define uset unordered_set #define umap unordered_map #define pii pair<int, int> #define ld long double #define pll pair<long long, long long> mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <typename T> inline T range(T l, T r) { return uniform_int_distribution<T>(l, r)(rng); } inline void setin(string s) { freopen(s.c_str(), "r", stdin); } inline void setout(string s) { freopen(s.c_str(), "w", stdout); } template <typename T> void Min(T &a, T b) { a = min(a, b); } template <typename T> void Max(T &a, T b) { a = max(a, b); } const int mod = 1e9 + 7; const int inf = 2e9; const int N = 5e5 + 15; int n, m, a[N]; vector <int> g[N]; bool used[N]; set <pii> cur; int deg[N], d[N]; int p[N], sz[N]; pii e[N]; int ans[N]; int find(int v) { if(v == p[v]) return v; return p[v] = find(p[v]); } void unio(int a, int b) { a = find(a); b = find(b); if(a != b) { if(sz[a] < sz[b]) swap(a, b); p[b] = a; sz[a] += sz[b]; } } inline int gt(int i, int v) { return e[i].f == v ? e[i].se : e[i].f; } void precheck(int v, int p = -1) { used[v] = true; for(int ind : g[v]) { int to = gt(ind, v); if(to == p) continue; if(used[to]) { if(d[to] > d[v]) continue; if((d[v] - d[to]) & 1) { cout << 0 << endl; exit(0); } } else { d[to] = d[v] + 1; precheck(to, v); } } } main() { for(int i = 1; i <= n; ++i) p[i] = i, sz[i] = 1; ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); // setin("input.txt"); cin >> n >> m; for(int i = 1; i <= n; ++i) cin >> a[i]; for(int i = 1; i <= m; ++i) { cin >> e[i].f >> e[i].se; g[e[i].f].pb(i); g[e[i].se].pb(i); } precheck(1); for(int i = 1; i <= n; ++i) deg[i] = g[i].size(), cur.insert({g[i].size(), i}); memset(used, 0, sizeof(used)); while(!cur.empty()) { int v = cur.begin()->se; if(deg[v] != 1) break; cur.erase(cur.begin()); used[v] = true; for(int ind : g[v]) { int to = gt(ind, v); if(used[to]) a[v] -= ans[ind] / 2; } for(int ind : g[v]) { int to = gt(ind, v); if(used[to]) continue; ans[ind] = 2 * a[v]; cur.erase({deg[to], to}); --deg[to]; cur.insert({deg[to], to}); } } for(int i = 1; i <= m; ++i) cout << ans[i] << endl; return 0; }

Compilation message (stderr)

pipes.cpp:117:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...