蒟蒻求助,9个点全MLE
查看原帖
蒟蒻求助,9个点全MLE
355559
FutureThx楼主2020/7/31 12:44

RT,lz已调吐。 马蜂清奇,大佬勿喷

#include <iostream>
using namespace std;
struct node
{
    int data;
    node* next_node;
};
node* head[10001];
void cr(int a,int x) {
    node* p;
    p = new node;
    p->data = a;
    p->next_node = NULL;
    if (head[x] == NULL) 
        head[x] = p;
    else {
        node* t;
        t = head[x];
        while (t->next_node != NULL)
            t = t->next_node;
        t->next_node = p;
    }
}
int t_cow[10001];
void bl(int x) {
    t_cow[x]++;
    node* t;
    t = head[x];
    while (t != NULL) {
        bl(t->data);
        t = t->next_node;
    }
}
int main(){
    int K, N, M;
    cin >> K >> N >> M;
    int cow[10001];
    for (int i = 1; i <= K; i++)cin >> cow[i];
    for (int i = 1; i <= M; i++) {
        int x, y;
        cin >> x >> y;
        cr(y, x);
    }
    for (int i = 1; i <= K; i++)
        bl(cow[i]);
    int t = 0;
    for (int i = 1; i <= N; i++) {
        if (t_cow[i] == K)
            t++;
    }
    cout << t;
    return 0;
}
2020/7/31 12:44
加载中...