This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
ll const N = 1e5 + 9;
ll C[N], C2[N], X[N];
bool odw[N];
vector<ll> G[N];
bool t = true;
map<pair<ll, ll>, ll> M;
pair<ll, ll> T[N];
void dfs(ll v) {
odw[v] = 1;
bool k = true;
for (ll i = 0; i < G[v].size(); i++) {
ll syn = G[v][i];
if (odw[syn] == 0) {
dfs(syn);
C2[v] += C[syn];
M[{v, syn}] = C[syn] * 2;
M[{syn, v}] = C[syn] * 2;
k = false;
}
}
if (k == true) C2[v] = C[v];
}
void task1(ll n, ll m) {
dfs(1);
for (ll i = 0; i < n; i++) {
if (C[i] != C2[i]) {
cout << "0\n";
return;
}
}
for (ll i = 0; i < m; i++) {
cout << M[T[i]] << "\n";
}
return;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, m;
cin >> n >> m;
for (ll i = 1; i <= n; i++)
cin >> C[i];
for (ll i = 0; i < m; i++) {
ll a, b;
cin >> a >> b;
G[a].push_back(b);
G[b].push_back(a);
T[i] = { a, b };
}
task1(n, m); //podzadanie za 30
}
Compilation message (stderr)
pipes.cpp: In function 'void dfs(ll)':
pipes.cpp:18:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for (ll i = 0; i < G[v].size(); i++) {
| ~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |