# ACM/ICPC World Finals 2013 A Self-Assembly

### 解法

00B+D+A-

B+ -> D-
B+ -> A+
D+ -> B-
D+ -> A+
A- -> B-
A- -> D-

``#include <cstdio>#include <cstdlib>#include <cstring>#include <queue>#include <algorithm>using namespace std;const int MAXM = 160500;const int MAXN = 50000;class Edge{    public:        int to;        int next;};Edge es[MAXM];int head[MAXN];int ent[MAXN];int N, n;char str[10];int et = -1;void addEdge(int u, int v){    et++;    es[et].to = v;    es[et].next = head[u];    head[u] = et;}void readin(){    memset(head, -1, sizeof(head));    scanf("%d", &n);    N = n+30;    int tmp;    for (int i = 1; i <= n; i++) {        scanf("%s", str);        if (str[1] == '+') {            tmp = str[0]-'A'+1;            addEdge(i, tmp+n);            ent[tmp+n]++;        } else if (str[1] == '-') {            tmp = str[0]-'A'+1;            addEdge(tmp+n, i);            ent[i]++;        }        if (str[3] == '+') {            tmp = str[2]-'A'+1;            addEdge(i, tmp+n);            ent[tmp+n]++;        } else if (str[3] == '-') {            tmp = str[2]-'A'+1;            addEdge(tmp+n, i);            ent[i]++;        }        if (str[5] == '+') {            tmp = str[4]-'A'+1;            addEdge(i, tmp+n);            ent[tmp+n]++;        } else if (str[5] == '-') {            tmp = str[4]-'A'+1;            addEdge(tmp+n, i);            ent[i]++;        }        if (str[7] == '+') {            tmp = str[6]-'A'+1;            addEdge(i, tmp+n);            ent[tmp+n]++;        } else if (str[7] == '-') {            tmp = str[6]-'A'+1;            addEdge(tmp+n, i);            ent[i]++;        }    }}void work(){    queue<int> ser;    for (int i = 1; i <= N; i++) {        if (!ent[i])            ser.push(i);    }    int root;    while(!ser.empty()) {        root = ser.front();        ser.pop();        for (int i = head[root]; i != -1; i = es[i].next) {            ent[es[i].to]--;            if (!ent[es[i].to])                ser.push(es[i].to);        }    }    for (int i = 1; i <= N; i++)        if (ent[i]) {            printf("unbounded");            return;        }    printf("bounded");}int main(){    readin();    work();    return 0;}``
0 0