답안 #864486

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
864486 2023-10-23T04:32:56 Z Requiem Amusement Park (CEOI19_amusementpark) C++17
7 / 100
1 ms 372 KB
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
#define INF 1e18
#define fi first
#define se second
#define endl "\n"
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define pi 3.14159265359
#define TASKNAME "amusepark"
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; } 
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; } 
using namespace std; 
typedef pair<int,int> ii; 
typedef pair<int,ii> iii; 
typedef vector<int> vi; 
const int MAXN = 3e2 + 9;
ii edge[MAXN];
int n,m,ans=0;
int degree[MAXN];
vector<int> g[MAXN];
bool visited[MAXN];
bool check(){
    for(int i=1;i<=n;i++){
        degree[i] = 0;
    }
    for(int i=1;i<=m;i++){
        g[edge[i].fi].pb(edge[i].se);
        degree[edge[i].se]++;
        // cout<<edge[i].fi<<' '<<edge[i].se<<endl;
    }
    // cout<<endl<<endl;
    queue<int> q;
    for(int i=1;i<=n;i++){

        if (degree[i] == 0) q.push(i);
    }
    vector<int> topo;
    
    while(!q.empty()){
        int u = q.front();
        topo.pb(u);
        q.pop();
        for(auto v: g[u]){
            degree[v]--;
            if (degree[v] == 0) q.push(v);
        }
    }
    return topo.size() == n;
}
void backtrack(int pos,int cost){
    if (pos==m+1){
        if (check()){
            // for(int i=1;i<=m;i++){
            //     cout<<edge[i].fi<<' '<<edge[i].se<<endl;
            // }
            // cout<<cost<<endl;
            // cout<<endl;
            ans += cost;
        }
        return;
    }
    swap(edge[pos].fi,edge[pos].se);
    backtrack(pos+1,cost+1);
    swap(edge[pos].fi,edge[pos].se);
    backtrack(pos+1,cost);
}
main() 
{ 
    fast; 
    // freopen(TASKNAME".inp","r",stdin); 
    // freopen(TASKNAME".out","w",stdout); 
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>edge[i].fi>>edge[i].se;
    }
    backtrack(1,0);
    cout<<ans<<endl;



} 

Compilation message

amusementpark.cpp: In function 'bool check()':
amusementpark.cpp:53:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   53 |     return topo.size() == n;
      |            ~~~~~~~~~~~~^~~~
amusementpark.cpp: At global scope:
amusementpark.cpp:72:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   72 | main()
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 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 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 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 372 KB Output is correct
12 Incorrect 1 ms 348 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 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 372 KB Output is correct
12 Incorrect 1 ms 348 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 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 372 KB Output is correct
12 Incorrect 1 ms 348 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 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 372 KB Output is correct
12 Incorrect 1 ms 348 KB Output isn't correct
13 Halted 0 ms 0 KB -