#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define FORD(i, a, b) for(int i = b; i >= a; --i)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define REPD(i, a, b) for(int i = b; i > a; -- i)
#define ALL(v) v.begin(),v.end()
#define next __next
#define left __left
#define right __right
#define prev __prev
const int MOD[6] = {(int)1e9 + 7, (int)1e9 + 2277, (int)1e9 + 5277, (int)1e9 + 8277, (int)1e9 + 9277, 998244353};
const int BASE[6] = {23309, 300, 330, 280, 2309, 256};
const int base = BASE[0];
const int mod = MOD[0];
void add(int &u, int v){
u += v;
if(u >= mod) u -= mod;
}
void sub(int &u, int v){
u -= v;
if(u < 0) u += mod;
}
void minimize(int &u, int v){
if(u > v) u = v;
}
void maximize(int &u, int v){
if(u < v) u = v;
}
void minimizell(long long &u, long long v){
if(u > v) u = v;
}
void maximizell(long long &u, long long v){
if(u < v) u = v;
}
const int maxN = 1e5 + 2;
const int maxM = 5e5 + 2;
const int maxK = 1e2 + 2;
const int INF = 1e9 + 8;
const long long INFLL = 1e18;
const int LOG = 16;
int N, M;
vector<pair<int, int>> adj[maxN];
pair<int, int> edge[maxM];
int deg[maxN];
bool del[maxN];
queue<int> listSource;
int res[maxM], c[maxN];
int st, ed, firstEdge;
int listEdge[maxN];
int node[maxN];
int cnt = 0;
void Dfs1(int u, int p){
for(pair<int, int> x : adj[u]){
int v = x.fi;
if(v != p){
Dfs1(v, u);
res[x.second] = 2 * c[v];
c[u] -= c[v];
}
}
}
void Dfs2(int u, int p, int id){
node[++cnt] = u;
listEdge[cnt] = id;
if(u == ed){
res[firstEdge] = c[st];
int d = 1;
FOR(i, 2, cnt){
res[firstEdge] += d * c[node[i]];
d *= -1;
}
FOR(i, 2, cnt){
res[listEdge[i]] = 2 * c[node[i - 1]] - res[listEdge[i - 1]];
}
FOR(i, 1, M)cout << res[i] << "\n";
exit(0);
}
for(pair<int, int> x : adj[u]){
int v = x.fi;
if(v == p)continue;
Dfs2(v, u, x.second);
}
--cnt;
}
int main(){
//freopen(".INP", "r", stdin);
//freopen(".OUT", "w", stdout);
//freopen(".INP", "w", stdout);
//freopen(".ANS", "w", stdout);
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> N >> M;
FOR(i, 1, N)cin >> c[i];
FOR(i, 1, M){
int u, v;
cin >> u >> v;
edge[i] = make_pair(u, v);
adj[u].push_back({v, i});
adj[v].push_back({u, i});
deg[u]++;
deg[v]++;
}
if(M > N){
cout << 0;
return 0;
}
if(M == N - 1){
Dfs1(1, 0);
FOR(i, 1, M)cout << res[i] << '\n';
return 0;
}
FOR(i, 1, N)if(deg[i] == 1){
if(deg[i] == 1){
listSource.push(i);
del[i] = true;
}
}
while(!listSource.empty()){
int u = listSource.front();
listSource.pop();
for(pair<int, int> x : adj[u]){
int v = x.fi;
if(del[v])continue;
c[v] -= c[u];
res[x.se] = 2 * c[u];
deg[v]--;
if(deg[v] == 1){
del[v] = true;
listSource.push(v);
}
}
}
int cnt = 0;
FOR(i, 1, N)if(del[i] == 0)++cnt;
if((cnt & 1) == 0){
cout << 0;
return 0;
}
FOR(i, 1, M){
int u = edge[i].fi, v = edge[i].se;
if(del[u] == false && del[v] == false){
st = u;
firstEdge = i;
break;
}
}
Dfs2(st, ed, firstEdge);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3932 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
33 ms |
8828 KB |
Output is correct |
5 |
Correct |
1 ms |
3932 KB |
Output is correct |
6 |
Correct |
1 ms |
3932 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
2 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
2 ms |
2896 KB |
Output is correct |
11 |
Correct |
3 ms |
2908 KB |
Output is correct |
12 |
Correct |
1 ms |
3932 KB |
Output is correct |
13 |
Correct |
34 ms |
7512 KB |
Output is correct |
14 |
Correct |
37 ms |
9552 KB |
Output is correct |
15 |
Correct |
37 ms |
10064 KB |
Output is correct |
16 |
Correct |
30 ms |
10076 KB |
Output is correct |
17 |
Correct |
36 ms |
10064 KB |
Output is correct |
18 |
Correct |
33 ms |
10076 KB |
Output is correct |
19 |
Correct |
35 ms |
13404 KB |
Output is correct |
20 |
Correct |
1 ms |
3932 KB |
Output is correct |
21 |
Correct |
2 ms |
2904 KB |
Output is correct |
22 |
Correct |
38 ms |
8788 KB |
Output is correct |
23 |
Correct |
27 ms |
7504 KB |
Output is correct |
24 |
Correct |
36 ms |
8712 KB |
Output is correct |
25 |
Correct |
32 ms |
7772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
14428 KB |
Output isn't correct |
2 |
Incorrect |
6 ms |
9564 KB |
Output isn't correct |
3 |
Correct |
25 ms |
9308 KB |
Output is correct |
4 |
Correct |
29 ms |
8792 KB |
Output is correct |
5 |
Correct |
26 ms |
9052 KB |
Output is correct |
6 |
Correct |
113 ms |
21332 KB |
Output is correct |
7 |
Incorrect |
8 ms |
14428 KB |
Output isn't correct |
8 |
Incorrect |
9 ms |
14428 KB |
Output isn't correct |
9 |
Correct |
1 ms |
3932 KB |
Output is correct |
10 |
Correct |
2 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
1 ms |
2652 KB |
Output is correct |
13 |
Correct |
1 ms |
2652 KB |
Output is correct |
14 |
Incorrect |
5 ms |
8536 KB |
Output isn't correct |
15 |
Incorrect |
5 ms |
8284 KB |
Output isn't correct |
16 |
Incorrect |
6 ms |
8284 KB |
Output isn't correct |
17 |
Correct |
1 ms |
3928 KB |
Output is correct |
18 |
Correct |
2 ms |
2652 KB |
Output is correct |
19 |
Correct |
2 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
2 ms |
2908 KB |
Output is correct |
22 |
Incorrect |
5 ms |
8284 KB |
Output isn't correct |
23 |
Incorrect |
42 ms |
14160 KB |
Output isn't correct |
24 |
Incorrect |
47 ms |
15456 KB |
Output isn't correct |
25 |
Correct |
25 ms |
8028 KB |
Output is correct |
26 |
Correct |
29 ms |
7624 KB |
Output is correct |
27 |
Correct |
29 ms |
7508 KB |
Output is correct |
28 |
Correct |
37 ms |
8020 KB |
Output is correct |
29 |
Correct |
96 ms |
17748 KB |
Output is correct |
30 |
Incorrect |
44 ms |
13904 KB |
Output isn't correct |
31 |
Incorrect |
49 ms |
17748 KB |
Output isn't correct |
32 |
Runtime error |
78 ms |
39396 KB |
Execution killed with signal 11 |
33 |
Correct |
28 ms |
8272 KB |
Output is correct |
34 |
Correct |
24 ms |
7504 KB |
Output is correct |
35 |
Correct |
29 ms |
7516 KB |
Output is correct |
36 |
Correct |
26 ms |
7764 KB |
Output is correct |
37 |
Correct |
104 ms |
21324 KB |
Output is correct |
38 |
Incorrect |
47 ms |
16468 KB |
Output isn't correct |
39 |
Runtime error |
85 ms |
41300 KB |
Execution killed with signal 11 |
40 |
Runtime error |
61 ms |
44372 KB |
Execution killed with signal 11 |
41 |
Correct |
25 ms |
9044 KB |
Output is correct |
42 |
Correct |
28 ms |
8536 KB |
Output is correct |
43 |
Correct |
28 ms |
8540 KB |
Output is correct |
44 |
Correct |
27 ms |
9040 KB |
Output is correct |
45 |
Correct |
81 ms |
19284 KB |
Output is correct |
46 |
Incorrect |
46 ms |
16724 KB |
Output isn't correct |
47 |
Runtime error |
64 ms |
44372 KB |
Execution killed with signal 11 |
48 |
Incorrect |
42 ms |
17748 KB |
Output isn't correct |
49 |
Correct |
28 ms |
9560 KB |
Output is correct |
50 |
Correct |
32 ms |
8784 KB |
Output is correct |
51 |
Correct |
24 ms |
8792 KB |
Output is correct |
52 |
Correct |
27 ms |
8612 KB |
Output is correct |
53 |
Correct |
84 ms |
19284 KB |
Output is correct |
54 |
Incorrect |
46 ms |
16208 KB |
Output isn't correct |