179632025-09-24 17:39:17algoproTestnevelés óracpp17Wrong answer 7/50122ms19352 KiB
// UUID: 1d3e393b-9d41-4a0f-9aee-2a5dff9962dc
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define fs first
#define sc second
#define pb push_back
#define pll pair<ll, ll>
#define vll vector<ll>
#define v2ll vector<vll>
#define pqll priority_queue<ll>

const ll mod = 1e9+7;
const ll inf = LONG_LONG_MAX;

ll n, k;
vector<pll> vp;
v2ll g;
vll be, ki;
queue<ll> q;

void solve()
{
    cin >> n >> k;
    vp.resize(k); g.resize(n); be.resize(n); ki.resize(n);
    for (ll i = 0; i < k; i++) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        ki[a]++; be[b]++;
        g[a].pb(b);
    }
    for (ll i = 0; i < n; i++)
        if (be[i] == 0)
            q.push(i);
    vll ans;
    while(!q.empty()) {
        ll a = q.front();
        q.pop();
        ans.pb(a);
        for (ll i : g[a]) {
            be[i]--;
            if (be[i] == 0)
                q.push(i);
        }
    }
    if (ans.size() != n) {
        cout << 0;
        return;
    }
    ll cnt = 1;
    for (ll i = 0; i < n-1; i++) {
        if (find(g[ans[i]].begin(), g[ans[i]].end(), ans[i+1]) == g[ans[i]].end())
            cnt *= 2;
    }
    cout << cnt << '\n';
    for (ll i : ans)
        cout << i+1 << ' ';
}
 
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}   
SubtaskSumTestVerdictTimeMemory
base7/50
1Accepted0/01ms500 KiB
2Wrong answer0/01ms316 KiB
3Wrong answer0/0107ms12212 KiB
4Wrong answer0/21ms316 KiB
5Wrong answer0/31ms316 KiB
6Wrong answer0/31ms316 KiB
7Wrong answer0/31ms316 KiB
8Accepted1/11ms316 KiB
9Wrong answer0/31ms316 KiB
10Wrong answer0/32ms316 KiB
11Wrong answer0/32ms564 KiB
12Accepted1/12ms564 KiB
13Accepted2/22ms564 KiB
14Wrong answer0/31ms316 KiB
15Accepted1/178ms9276 KiB
16Wrong answer0/387ms13100 KiB
17Wrong answer0/526ms12840 KiB
18Wrong answer0/1104ms19352 KiB
19Accepted2/285ms9592 KiB
20Wrong answer0/3122ms15532 KiB
21Wrong answer0/4100ms15532 KiB
22Wrong answer0/497ms15528 KiB