| Time Limit: 1000MS | Memory Limit: 10000K | |||
| Total Submissions: 3829 | Accepted: 1710 | Special Judge | ||
Description
Input
Output
Sample Input
1 6 8 1 2 1 3 2 4 2 5 3 4 3 6 4 6 5 6
Sample Output
3 1 4 5
Source
Source Code Problem: 1419 Memory: 304K Time: 16MS Language: C++ Result: Accepted Source Code
#include <iostream>
#include <cstring>
#include <cstdio>
#define BLACK 0
#define WHITE 1
using namespace std;
const int MAX=100+10;
int n, k;
int g[MAX][MAX];
int vis[MAX], color[MAX];
int ans=0;
void init()
{
ans = 0;
memset(color, BLACK, sizeof(color));
memset(g, 0, sizeof(g));
memset(vis,0, sizeof(vis));
}
void read()
{
cin >> n >> k;
int u, v;
for(int i=1; i <= k; i++)
{
cin >> u >> v;
g[u][v] = g[v][u] = 1;
}
}
int writeWhite(int u)
{
int count=0;
for(int i=u; i <= n+u-1; i++)
{
int pos = i%n;
if(!pos) pos=n;
if(color[pos]==BLACK)
{
count++;
for(int v=1; v <= n; v++ )
if(g[pos][v])
color[v]=WHITE;
}
}
return count;
}
void solve()
{
int ans=0;
int resu[MAX];
for(int i=1; i <= n; i++)
{
memset(color, BLACK, sizeof(color));
int temp = writeWhite(i);
if(temp > ans)
{
ans = temp;
int length=0;
for(int j=1; j <= n; j++)
if(color[j]==BLACK)
resu[length++]=j;
}
}
cout << ans << endl;
for(int i=0; i < ans; i++)
cout << resu[i] <<" ";
cout << endl;
}
int main()
{
// freopen("in.txt","r",stdin);
int nCase;
cin >> nCase;
while(nCase--)
{
init();
read();
solve();
}
return 0;
}poj 1419 Graph Coloring 图着色问题,布布扣,bubuko.com
原文:http://blog.csdn.net/china_zoujinyong/article/details/21552239