답안 #1048717

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1048717 2024-08-08T09:13:57 Z anton Amusement Park (CEOI19_amusementpark) C++17
19 / 100
3000 ms 456 KB
#include<bits/stdc++.h>

using namespace std;

#define int long long
#define pii pair<int, int>
int N, M;
const int MOD = 998244353;
struct Edge{
    int sides[2];
    int dir= 0;
    Edge(){};
    Edge(int a, int b){
        sides[0] = a;
        sides[1] =b;
    }
    int dest(){
        return sides[dir];
    }
    int origin(){
        return sides[dir^1];
    }
};

vector<vector<int>> adj;
vector<Edge> edges; 


vector<int> ch(int i){
    vector<int> res;
    for(auto eid : adj[i]){
        Edge edge= edges[eid];
        if(i == edge.origin()){
            res.push_back(edge.dest());
        }
    }
    return res;
}

bool is_DAG(int mask){
    for(int i = 0; i<M; i++){
        edges[i].dir = (mask>>i)& 1;
    }
    vector<int> free;
    vector<int> in_deg(N);
    for(int i = 0; i<N; i++){
        for(auto c: ch(i)){
            in_deg[c]++;
        }
    }
    for(int i = 0; i<N; i++){
        if(in_deg[i]==0){
            free.push_back(i);
        }
    }

    while(free.size()>0){
        int i = free.back();
        free.pop_back();
        for(auto c: ch(i)){
            in_deg[c]--;
            if(in_deg[c]==0){
                free.push_back(c);
            }
        }
    }

    for(int i = 0; i<N; i++){
        if(in_deg[i]>0){
            return false;
        }
    }
    return true;
}
signed main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);

    cin>>N>>M;

    adj.resize(N);

    for(int i = 0; i<M; i++){
        int a, b;
        cin>>a>>b;
        a--;b--;
        edges.push_back(Edge(a, b));
        adj[a].push_back(i);
        adj[b].push_back(i);
    }

    int RES =0;
    for(int mask =1; mask < (1<<M); mask++){
        if(is_DAG(mask)){
            //cout<<bitset<3>(mask)<<endl;
            RES = (RES + __builtin_popcount(mask));
        }
    }

    cout<<RES<<endl;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 13 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 13 ms 452 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 16 ms 456 KB Output is correct
30 Correct 109 ms 432 KB Output is correct
31 Correct 1297 ms 456 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 2 ms 348 KB Output is correct
35 Correct 30 ms 348 KB Output is correct
36 Correct 488 ms 456 KB Output is correct
37 Execution timed out 3054 ms 348 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 13 ms 452 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 16 ms 456 KB Output is correct
30 Correct 109 ms 432 KB Output is correct
31 Correct 1297 ms 456 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 2 ms 348 KB Output is correct
35 Correct 30 ms 348 KB Output is correct
36 Correct 488 ms 456 KB Output is correct
37 Execution timed out 3054 ms 348 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 13 ms 452 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 16 ms 456 KB Output is correct
30 Correct 109 ms 432 KB Output is correct
31 Correct 1297 ms 456 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 2 ms 348 KB Output is correct
35 Correct 30 ms 348 KB Output is correct
36 Correct 488 ms 456 KB Output is correct
37 Execution timed out 3054 ms 348 KB Time limit exceeded
38 Halted 0 ms 0 KB -