蓝书326

//看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker,"/STACK:102400000,102400000")
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define haha printf("haha\n")
const int maxn = 1e5 + ;
struct TwoSat{
int n, c, s[maxn * ];
bool mark[maxn << ];
vector<int> G[maxn << ]; void init(int n){
this->n = n;
for (int i = ; i < * n; i++) G[i].clear();
memset(mark, false, sizeof(mark));
} void add_edge(int x, int xval, int y, int yval){
x = x * + xval, y = y * + yval;
G[x ^ ].pb(y), G[y ^ ].pb(x);
} bool dfs(int x){
if (mark[x ^ ]) return false;
if (mark[x]) return true;
mark[x] = true;
s[c++] = x;
for (int i = ; i < G[x].size(); i++){
if (!dfs(G[x][i])) return false;
}
return true;
} bool solve(){
for (int i = ; i < n * ; i += ){
if (!mark[i] && !mark[i + ]){
c = ;
if (!dfs(i)){
while (c) mark[s[--c]] = false;
if (!dfs(i + )) return false;
}
}
}
return true;
} };
TwoSat sat2;
int n, m;
int age[maxn]; int main(){
while (scanf("%d%d", &n, &m) && (n + m) > ){
sat2.init(n);
int tot = ;
for (int i = ; i < n; i++){
scanf("%d", age + i);
tot += age[i];
}
/*
假设A和B都是1,C是0
if两者属于同一个任务,那么,两者不能分配到同一个任务,
所以两者不能同时为true和同时为false if两者属于不同的任务,那么两者不能同时为false
*/
for (int i = ; i < m; i++){
int u, v; scanf("%d%d", &u, &v);
u--, v--;
if (u == v) continue;
int tyu = age[u] * n < tot, tyv = age[v] * n < tot;
sat2.add_edge(u, , v, );
if (tyu == tyv)
sat2.add_edge(u, , v, );
}
if (!sat2.solve()) puts("No solution.");
else {
for (int i = ; i < n; i++){
if (sat2.mark[i * ]) puts("C");
if (sat2.mark[i * + ]) {
if (age[i] * n < tot) puts("B");
else puts("A");
}
}
}
}
return ;
}

最新文章

  1. js继承相关
  2. Python检测IP合法 是否为公网IP
  3. Magento订单打印(pdf格式)
  4. Python学习总结15:时间模块datetime &amp; time &amp; calendar (二)
  5. Zabbix监控Linux磁盘I/O
  6. 企业生产环境下不同业务的linux分区建议
  7. hadoop2.2编程:从default mapreduce program 来理解mapreduce
  8. The Contiki build system 编译系统
  9. shell中eval命令妙用——变量嵌套替换
  10. 【Android】自带Theme
  11. PuTsangTo
  12. pthread_cond_wait的spurious wakeup问题
  13. ajax请求window.open()被拦截
  14. Web安全之XSS Platform搭建及使用实践
  15. JavaFX 简介
  16. 《Oracle DBA工作笔记:运维、数据迁移与性能调优》 PDF 下载
  17. ID3-C45-CART
  18. python 复数类型
  19. pseudotime专题
  20. Extjs获取Form中的数据

热门文章

  1. FPGA论文
  2. 给个理由走下去——读《我是一只IT小小鸟》有感
  3. Rsyslog的三种传输协议简要介绍
  4. 第8章 Linux磁盘与文件系统管理
  5. PHP中访问控制修饰符
  6. kafka 基础知识梳理-kafka是一种高吞吐量的分布式发布订阅消息系统
  7. Kafka生产者各种启动参数说明
  8. 【前端学习笔记】call、apply、bind方法
  9. bzoj4754[JSOI2016]独特的树叶
  10. bzoj4798[CEOI2015] Calvinball championship