# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
120955 |
2019-06-25T20:06:06 Z |
thiago4532 |
Pipes (BOI13_pipes) |
C++17 |
|
379 ms |
29880 KB |
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5 + 10;
const int maxm = 5e5 + 10;
vector<int> grafo[maxn];
int n;
int s[maxn];
map<pair<int, int>, int> mapa;
int val[maxn], ans[maxn];
int grau[maxn];
namespace tree{
int nivel[maxn], pai[maxn], soma[maxn];
void dfs(int u, int p = 0) {
pai[u] = p;
for(auto v : grafo[u]) {
if(v == p) continue;
nivel[v] = nivel[u] + 1;
dfs(v, u);
}
}
};
namespace cycle {
vector<int> grafo[maxn];
int st;
bool mark[maxn];
vector<int> ordem;
void dfs(int u) {
mark[u] = true;
ordem.push_back(u);
for(auto v : grafo[u]) {
if(!mark[v]) dfs(v);
}
}
void solve() {
dfs(st);
if(ordem.size() % 2 == 0){
cout << "0\n";
return;
}
int x = 0;
int sig = 1;
for(auto& u : ordem){
x += s[u]*sig;
sig *= -1;
}
x/=2;
ans[mapa[{ordem[0], ordem.back()}]] = x;
// cout << ordem[0] << " " << ordem.back() << ": " << ans[mapa[{ordem[0], ordem.back()}]] << "\n";
for(int i = 0; i < (int)ordem.size() - 1; i++) {
ans[mapa[{ordem[i], ordem[i+1]}]] = s[ordem[i]] - x;
// cout << ordem[i] << " " << ordem[i+1] << ": " << s[ordem[i]] - x << "\n";
x = s[ordem[i]] - x;
}
for(int i=1;i<=n;i++){
cout << ans[i] << "\n";
}
}
};
int32_t main() {
int m;
cin >> n >> m;
if(m > n) {
cout << "0\n";
return 0;
}
int total = 0;
for(int i=1;i<=n;i++)
cin >> s[i], s[i] *= 2, total += s[i];
for(int i=1;i<=m;i++) {
int a, b;
cin >> a >> b;
grafo[a].push_back(b);
grafo[b].push_back(a);
mapa[{a, b}] = i;
mapa[{b, a}] = i;
grau[a]++;
grau[b]++;
}
if(n - 1 == m) {
tree::dfs(1);
vector<pii> arr;
for(int i=1;i<=n;i++)
arr.push_back({tree::nivel[i], i});
sort(arr.begin(), arr.end(), greater<pii>());
for(auto e : arr) {
int v = e.second;
int u = tree::pai[v];
tree::soma[u] += (s[v] - tree::soma[v]);
ans[mapa[{u, v}]] = (s[v] - tree::soma[v]);
}
if(tree::soma[1] != s[1]){
cout << "0\n";
return 0;
}
for(int i=1;i<=m;i++)
cout << ans[i] << "\n";
}else { // n == m
bool only_cycle = true; // only cycle
for(int i=1;i<=n;i++)
if(grau[i] == 1) only_cycle = false;
if(only_cycle) {
for(int i=1;i<=n;i++)
cycle::grafo[i] = grafo[i];
cycle::st = 1;
cycle::solve();
}else {
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5120 KB |
Output is correct |
2 |
Correct |
7 ms |
5120 KB |
Output is correct |
3 |
Correct |
7 ms |
5248 KB |
Output is correct |
4 |
Correct |
366 ms |
28004 KB |
Output is correct |
5 |
Correct |
6 ms |
5120 KB |
Output is correct |
6 |
Correct |
6 ms |
5120 KB |
Output is correct |
7 |
Correct |
6 ms |
5120 KB |
Output is correct |
8 |
Correct |
6 ms |
5248 KB |
Output is correct |
9 |
Correct |
7 ms |
5248 KB |
Output is correct |
10 |
Correct |
7 ms |
5248 KB |
Output is correct |
11 |
Correct |
8 ms |
5248 KB |
Output is correct |
12 |
Correct |
8 ms |
5376 KB |
Output is correct |
13 |
Correct |
297 ms |
23400 KB |
Output is correct |
14 |
Correct |
326 ms |
26856 KB |
Output is correct |
15 |
Correct |
347 ms |
28132 KB |
Output is correct |
16 |
Correct |
285 ms |
24660 KB |
Output is correct |
17 |
Correct |
361 ms |
28164 KB |
Output is correct |
18 |
Correct |
376 ms |
28104 KB |
Output is correct |
19 |
Correct |
379 ms |
29880 KB |
Output is correct |
20 |
Correct |
5 ms |
5120 KB |
Output is correct |
21 |
Correct |
7 ms |
5248 KB |
Output is correct |
22 |
Correct |
374 ms |
28212 KB |
Output is correct |
23 |
Correct |
273 ms |
23396 KB |
Output is correct |
24 |
Correct |
348 ms |
28232 KB |
Output is correct |
25 |
Correct |
287 ms |
24352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
4992 KB |
Output isn't correct |
2 |
Incorrect |
7 ms |
5248 KB |
Output isn't correct |
3 |
Incorrect |
236 ms |
21640 KB |
Output isn't correct |
4 |
Correct |
6 ms |
4992 KB |
Output is correct |
5 |
Correct |
5 ms |
4992 KB |
Output is correct |
6 |
Correct |
5 ms |
4992 KB |
Output is correct |
7 |
Incorrect |
6 ms |
5120 KB |
Output isn't correct |
8 |
Incorrect |
6 ms |
5120 KB |
Output isn't correct |
9 |
Incorrect |
5 ms |
4992 KB |
Output isn't correct |
10 |
Correct |
6 ms |
4992 KB |
Output is correct |
11 |
Correct |
6 ms |
4992 KB |
Output is correct |
12 |
Correct |
5 ms |
4992 KB |
Output is correct |
13 |
Correct |
5 ms |
4992 KB |
Output is correct |
14 |
Incorrect |
6 ms |
5120 KB |
Output isn't correct |
15 |
Incorrect |
7 ms |
5248 KB |
Output isn't correct |
16 |
Incorrect |
6 ms |
5120 KB |
Output isn't correct |
17 |
Incorrect |
7 ms |
5248 KB |
Output isn't correct |
18 |
Correct |
6 ms |
4992 KB |
Output is correct |
19 |
Correct |
5 ms |
5120 KB |
Output is correct |
20 |
Correct |
6 ms |
5120 KB |
Output is correct |
21 |
Correct |
5 ms |
4992 KB |
Output is correct |
22 |
Incorrect |
8 ms |
5248 KB |
Output isn't correct |
23 |
Incorrect |
207 ms |
19164 KB |
Output isn't correct |
24 |
Incorrect |
248 ms |
22648 KB |
Output isn't correct |
25 |
Incorrect |
239 ms |
21648 KB |
Output isn't correct |
26 |
Correct |
6 ms |
4992 KB |
Output is correct |
27 |
Correct |
6 ms |
4992 KB |
Output is correct |
28 |
Correct |
5 ms |
4992 KB |
Output is correct |
29 |
Correct |
6 ms |
4992 KB |
Output is correct |
30 |
Incorrect |
241 ms |
22008 KB |
Output isn't correct |
31 |
Incorrect |
237 ms |
22264 KB |
Output isn't correct |
32 |
Incorrect |
262 ms |
22776 KB |
Output isn't correct |
33 |
Incorrect |
254 ms |
22492 KB |
Output isn't correct |
34 |
Correct |
6 ms |
4992 KB |
Output is correct |
35 |
Correct |
6 ms |
4992 KB |
Output is correct |
36 |
Correct |
5 ms |
4992 KB |
Output is correct |
37 |
Correct |
6 ms |
5120 KB |
Output is correct |
38 |
Incorrect |
257 ms |
22460 KB |
Output isn't correct |
39 |
Incorrect |
254 ms |
22776 KB |
Output isn't correct |
40 |
Incorrect |
251 ms |
22520 KB |
Output isn't correct |
41 |
Incorrect |
256 ms |
22404 KB |
Output isn't correct |
42 |
Correct |
5 ms |
4992 KB |
Output is correct |
43 |
Correct |
6 ms |
4992 KB |
Output is correct |
44 |
Correct |
5 ms |
5000 KB |
Output is correct |
45 |
Correct |
6 ms |
5120 KB |
Output is correct |
46 |
Incorrect |
372 ms |
22268 KB |
Output isn't correct |
47 |
Incorrect |
255 ms |
22588 KB |
Output isn't correct |
48 |
Incorrect |
244 ms |
22496 KB |
Output isn't correct |
49 |
Incorrect |
256 ms |
21752 KB |
Output isn't correct |
50 |
Correct |
6 ms |
4992 KB |
Output is correct |
51 |
Correct |
6 ms |
4992 KB |
Output is correct |
52 |
Correct |
6 ms |
4992 KB |
Output is correct |
53 |
Correct |
6 ms |
4992 KB |
Output is correct |
54 |
Incorrect |
270 ms |
22152 KB |
Output isn't correct |