제출 #489907

#제출 시각UTC-0아이디문제언어결과실행 시간메모리
4899072021-11-25 03:58:49SirCovidThe19thPipes (BOI13_pipes)C++17
100 / 100
399 ms54872 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 mN = 1e5 + 5, mM = 5e5 + 5;
int n, m, cnt, st; long long A[mN], ans[mM], altSm; bool vis[mN]; set<pii> adj[mN];
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] * 2; A[nxt.f] -= A[cur];
adj[cur].clear(); 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...