竟然还涨分了。。。rank500+还能涨我rating是有多低。。。
AB不写了
C:类似找规律,具体证明看edtorial
#include<bits/stdc++.h> using namespace std; const int N = 200010; int m; struct data { int b, id; bool friend operator < (data A, data B) { return A.b < B.b; } } x[N], y[N]; int ans[N]; int main() { scanf("%d", &m); for(int i = 1; i <= m; ++i) { scanf("%d", &x[i].b); x[i].id = i; } for(int i = 1; i <= m; ++i) { scanf("%d", &y[i].b); y[i].id = i; } sort(y + 1, y + m + 1); sort(x + 1, x + m + 1); for(int i = 1; i <= m; ++i) ans[y[i].id] = x[m - i + 1].b; for(int i = 1; i <= m; ++i) printf("%d ", ans[i]); return 0; }
D:首先度数是奇数是不行的,这样是无解,所以我们拿出一个-1让度数变成偶数,然后实行染色,如果当前度数和是偶数就不连,是奇数就得连
#include<bits/stdc++.h> using namespace std; const int N = 300010; int n, m, cnt; int a[N], vis[N], b[N]; vector<int> G[N], e[N], ans; bool flag; void dfs(int u) { vis[u] = 1; if(a[u] == 1) b[u] = 1; for(int i = 0; i < G[u].size(); ++i) { int v = G[u][i]; if(vis[v]) continue; dfs(v); if(b[v] & 1) ans.push_back(e[u][i]); b[u] += b[v]; } } int main() { int pos = -1; scanf("%d%d", &n, &m); for(int i = 1; i <= n; ++i) { scanf("%d", &a[i]); if(a[i] == 1) ++cnt; if(a[i] == -1) pos = i; } for(int i = 1; i <= m; ++i) { int u, v; scanf("%d%d", &u, &v); G[u].push_back(v); G[v].push_back(u); e[u].push_back(i); e[v].push_back(i); } if(cnt & 1) { if(pos == -1) { puts("-1"); return 0; } a[pos] = 1; } dfs(1); printf("%d\n", ans.size()); sort(ans.begin(), ans.end()); for(int i = 0; i < ans.size(); ++i) printf("%d\n", ans[i]); return 0; }
editorial给太晚,差评
时间: 2024-10-12 08:36:11