uva 1391 Astronauts(2-SAT)
2024-10-08 17:59:55
/*翻译好题意 n个变量 不超过m*2句话*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#define maxn 200010
using namespace std;
int n,m,f[maxn],c,s[maxn],age[maxn],sum,a,b;
vector<int>G[maxn];
bool Judge(int a,int b)
{
if(age[a]*n<sum&&age[b]*n<sum)return ;
if(age[a]*n>=sum&&age[b]*n>=sum)return ;
return ;
}
void Add(int x,int a,int y,int b)
{
x=x*+a;y=y*+b;
G[x^].push_back(y);
G[y^].push_back(x);
}
bool Dfs(int x)
{
if(f[x^])return ;if(f[x])return ;
f[x]=;s[c++]=x;
for(int i=;i<G[x].size();i++)
if(!Dfs(G[x][i]))return ;
return ;
}
bool Solve()
{
for(int i=;i<n*;i+=)
{
if(f[i]||f[i+])continue;c=;
if(!Dfs(i))
{
while(c>)f[s[--c]]=;
if(!Dfs(i+))return ;
}
}
return ;
}
int main()
{
while()
{
memset(f,,sizeof(f));sum=;
for(int i=;i<n*;i++)G[i].clear();
scanf("%d%d",&n,&m);if(n==&&m==)break;
for(int i=;i<n;i++)
scanf("%d",&age[i]),sum+=age[i];
for(int i=;i<=m;i++)
{
scanf("%d%d",&a,&b);a--;b--;
if(a==b)continue;Add(a,,b,);
if(Judge(a,b))Add(a,,b,);
}
if(Solve()==)printf("No solution\n");
else for(int i=;i<n;i++)
{
if(f[i*])printf("C\n");
else if(age[i]*n<sum)printf("B\n");
else printf("A\n");
}
}
return ;
}
最新文章
- APUE环境配置
- Javascript中String()与new String()的差异
- java集合类的学习(二)
- GNU/Linux复习笔记(1)
- Excel scientific notation issue
- fork和execve
- [转]centos中wget的使用方法
- 小王子浅读Effective javascript(一)了解javascript版本
- Codeforces 377
- DataView.RowFilter筛选DataTable中的数据
- 【转】Open Live Writer 插件更新
- android的原理,为什么不需要手动关闭程序
- 如何重载浏览器 onload 事件后加载的资源文件
- iOS 主动抛出异常
- JS的for循环小例子
- OBS 录制视频 自己留存
- ubuntu16下的/etc/resolv.conf重置的解决方案
- Paxos算法细节详解(一)
- 25个增强iOS应用程序性能的提示和技巧 — 中级篇
- javascript---我对闭包的理解