제출 #489857

#제출 시각UTC-0아이디문제언어결과실행 시간메모리
4898572021-11-25 01:48:03SirCovidThe19thPipes (BOI13_pipes)C++17
70.19 / 100
1096 ms113000 KiB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define pii pair<int, int>
#define f first
#define s second
const int mx = 1e5 + 5;
int n, m, st = -1, cnt; long long A[mx], ans[mx], altSm; bool vis[mx]; set<pii> adj[mx];
void compressLeaves(){
queue<int> q;
FOR(i, 0, n) if (adj[i].size() == 1) q.push(i);
while (!q.empty()){
int cur = q.front(); q.pop();
if (adj[cur].empty()) continue;
pii nxt = *adj[cur].begin();
ans[nxt.s] = A[cur]; A[nxt.f] -= A[cur];
adj[nxt.f].erase({cur, nxt.s});
if (adj[nxt.f].size() == 1) q.push(nxt.f);
}
}
void dfs(int cur, bool parity){
altSm += !parity ? A[cur] : -A[cur]; vis[cur] = 1;
for (pii nxt : adj[cur]) if (!vis[nxt.f]) dfs(nxt.f, !parity);
}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...