답안 #1114075

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114075 2024-11-18T07:30:25 Z n3rm1n Amusement Park (CEOI19_amusementpark) C++17
0 / 100
1 ms 336 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN = 20;
void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int n, m;
int from[MAXN], to[MAXN];
void read()
{
    cin >> n >> m;
    for (int i = 1; i <= m; ++ i)
        cin >> from[i] >> to[i];
}
int order[MAXN], used[MAXN], visited[MAXN], in_cycle[MAXN]; /// na koq poziciq e i
long long ans = 0, imp = 0;
const long long mod = 998244353;
vector < int > g[MAXN];
void dfs(int beg)
{
    visited[beg] = 1;
    in_cycle[beg] = 1;
    for (auto nb: g[beg])
    {
        if(!visited[nb])dfs(nb);
        else if(in_cycle[nb])imp = 1;
    }
    in_cycle[beg] = 0;
}
void check()
{
    for (int i = 1; i <= n; ++ i)
        g[i].clear();

    int cnt = 0;
    for (int i = 1; i <= m; ++ i)
    {
        if(order[from[i]] > order[to[i]])
            g[from[i]].push_back(to[i]);
        else
        {
            cnt ++;
            g[to[i]].push_back(from[i]);
        }
    }
    memset(visited, 0, sizeof(visited));
    memset(in_cycle, 0, sizeof(in_cycle));
    imp = 0;
    for (int i = 1; i <= n; ++ i)
    {
        if(visited[order[i]])continue;
        dfs(visited[order[i]]);
    }
    if(imp)return;
    ans += cnt;
    ans %= mod;
}
void gen(int pos)
{
    if(pos > n)
    {
        check();
        return;
    }
    for (int i = 1; i <= n; ++ i)
    {
        if(used[i])continue;
        order[pos] = i;
        used[i] = 1;
        gen(pos+1);
        used[i] = 0;
    }
}
int main()
{
    speed();
    read();
    gen(1);
    cout << ans << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 1 ms 336 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 1 ms 336 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 1 ms 336 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 1 ms 336 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 1 ms 336 KB Output isn't correct
4 Halted 0 ms 0 KB -