QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#485146#8593. Coinfractal0 5ms30632kbC++172.6kb2024-07-20 13:54:102024-07-20 13:54:10

Judging History

你现在查看的是最新测评结果

  • [2024-07-20 13:54:10]
  • 评测
  • 测评结果:0
  • 用时:5ms
  • 内存:30632kb
  • [2024-07-20 13:54:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define make_unique(x) sort(all(x)), x.erase(unique(all(x)), x.end())

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 Rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 1e6 + 200;
const int M = 1e6;
const int inf = 2e9 + 3;
const ll INF = 1e18;

int n, m;
vector<int> g[N];

int can[1001][1001];
int ans[N], now[N], d[N];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) 
        ans[i] = -1;
    if (n <= 0) {
        vector<int> x(m), y(m);
        for (int i = 0; i < m; ++i) {
            cin >> x[i] >> y[i];
            now[x[i]] += (can[x[i]][y[i]] == 0);
            now[y[i]] += (can[x[i]][y[i]] == 0);
            can[x[i]][y[i]] = 1;
            for (int v = 1; v <= n; ++v) {
                if (can[y[i]][v]) {
                    now[v] += can[x[i]][v] == 0;
                    now[x[i]] += can[x[i]][v] == 0;
                    can[x[i]][v] = 1;
                }
                if (can[v][x[i]]) {
                    now[v] += can[v][y[i]] == 0;
                    now[y[i]] += can[v][y[i]] == 0;
                    can[v][y[i]] = 1;
                }
            }
            for (int v = 1; v <= n; ++v) if (now[v] == n - 1) ans[v] = i + 1, now[v] = n;
        }
        for (int i = 1; i <= n; ++i)
            cout << ans[i] << " \n"[i == n];
        return 0;
    }
    for (int i = 1, x, y; i <= m; ++i) {
        cin >> x >> y;
        g[x].push_back(y);
        d[y]++;
    }
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    for (int i = 1; i <= n; ++i) {
        q.push({d[i], i});
    }
    while (q.size()) {
        auto [x, v] = q.top();
        q.pop();
        if (x > d[v]) continue;
        vector<int> kek;
        for (auto u : g[v]) {
            kek.push_back(u);
        }
        if (q.size() && q.top().F == 0) {
            while (q.size() && q.top().F == 0) {
                for (auto u : g[q.top().S]) kek.push_back(u);
                q.pop();
            }
        }
        else {
            ans[v] = m;
        }
        for (auto u : kek) {
            d[u]--;
            q.push({d[u], u});
        }
    }
    for (int i = 1; i <= n; ++i)
        cout << ans[i] << " \n"[i == n];
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Acceptable Answer
time: 3ms
memory: 30204kb

input:

4 4
2 4
3 1
4 1
2 3

output:

4 4 -1 -1

result:

points 0.50 -1 correct

Test #2:

score: 3
Acceptable Answer
time: 5ms
memory: 30632kb

input:

6 8
1 5
5 4
6 2
2 5
4 3
6 1
6 5
2 1

output:

8 8 8 8 8 8

result:

points 0.50 -1 correct

Test #3:

score: 6
Accepted
time: 0ms
memory: 29568kb

input:

2 1
1 2

output:

1 1

result:

ok ac

Test #4:

score: 0
Wrong Answer
time: 0ms
memory: 29520kb

input:

6 12
1 5
5 4
6 2
2 5
4 3
6 5
1 5
1 5
2 4
6 3
1 3
4 3

output:

-1 12 12 12 12 -1

result:

wrong answer wa

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%