제출 #285709

#제출 시각아이디문제언어결과실행 시간메모리
285709kostia244Pipes (BOI13_pipes)C++17
44.07 / 100
226 ms33528 KiB
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
using ll = long long;
using namespace std;
const int maxn = 1<<19;
int n, m;
vector<array<int, 2>> g[maxn];
ll val[maxn];
int vis[maxn], C[maxn], h[maxn], back = -1, bb;
ll s = 0;
ll dfs(int v, int p) {
	ll cur = C[v];
	vis[v] = 1;
	if(h[v]&1) s -= v;
	else s += v;
	for(auto &[i, id] : g[v]) if(i != p) {
		if(!vis[i]) {
			h[i] = h[v]+1;
			ll t = dfs(i, v);
			cur += t;
			val[id] = t;
		} else if(h[i] < h[v]) {
			if(back != -1 || (h[i]&1) != (h[v]&1)) {cout << "0\n", exit(0);}
			back = id, bb = h[v]&1;
		}
	}
	return -cur;
}
signed main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> C[i];
	for(int f, t, i = 0; i < m; i++) {
		cin >> f >> t;
		g[f].push_back({t, i});
		g[t].push_back({f, i});
	}
	dfs(1, 1);
	if(back != -1) val[back] = bb?s:-s;
	for(int i = 0; i < m; i++) cout << 2ll*val[i] << "\n"; cout << endl;
}
//?VK
//??V
//K?

컴파일 시 표준 에러 (stderr) 메시지

pipes.cpp: In function 'int main()':
pipes.cpp:41:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   41 |  for(int i = 0; i < m; i++) cout << 2ll*val[i] << "\n"; cout << endl;
      |  ^~~
pipes.cpp:41:57: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   41 |  for(int i = 0; i < m; i++) cout << 2ll*val[i] << "\n"; cout << endl;
      |                                                         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...