QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#485143#8593. Coinfractal3 7ms33316kbC++172.6kb2024-07-20 13:50:292024-07-20 13:50:29

Judging History

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

  • [2024-07-20 13:50:29]
  • 评测
  • 测评结果:3
  • 用时:7ms
  • 内存:33316kb
  • [2024-07-20 13:50:29]
  • 提交

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 <= 1000) {
        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: 3
Acceptable Answer

Test #1:

score: 6
Accepted
time: 3ms
memory: 32192kb

input:

4 4
2 4
3 1
4 1
2 3

output:

3 4 -1 -1

result:

ok ac

Test #2:

score: 3
Acceptable Answer
time: 0ms
memory: 31716kb

input:

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

output:

8 8 6 6 5 6

result:

points 0.50 -1 correct

Test #3:

score: 6
Accepted
time: 6ms
memory: 31920kb

input:

2 1
1 2

output:

1 1

result:

ok ac

Test #4:

score: 3
Acceptable Answer
time: 7ms
memory: 32616kb

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 -1 6 6 5 -1

result:

points 0.50 -1 correct

Test #5:

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

input:

7 20
1 6
6 3
1 4
1 5
1 7
1 2
1 5
2 3
4 5
7 2
2 4
5 3
6 3
1 3
4 3
7 5
2 6
4 6
7 2
7 5

output:

6 17 12 18 -1 -1 17

result:

ok ac

Test #6:

score: 6
Accepted
time: 2ms
memory: 32308kb

input:

7 20
5 6
1 3
3 6
4 1
7 4
2 5
4 3
2 6
7 5
4 6
2 6
2 1
4 5
1 3
1 5
7 1
7 6
4 1
7 6
3 6

output:

15 -1 -1 -1 -1 6 -1

result:

ok ac

Test #7:

score: 6
Accepted
time: 3ms
memory: 33212kb

input:

7 20
7 6
4 5
6 4
3 6
4 1
6 2
3 5
5 2
7 6
1 2
3 6
6 4
7 1
6 1
7 1
4 5
3 6
3 5
4 5
3 1

output:

-1 10 -1 8 -1 6 -1

result:

ok ac

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

50%
Acceptable Answer

Test #8:

score: 8
Acceptable Answer
time: 3ms
memory: 32040kb

input:

20 100
5 20
4 5
18 16
1 13
14 9
11 19
6 4
7 20
16 11
8 13
4 5
16 9
12 14
7 12
11 3
9 11
9 11
13 6
3 10
12 9
13 4
20 12
13 6
18 11
5 7
5 7
15 18
12 15
17 13
15 18
3 2
11 2
11 2
15 19
4 19
14 19
14 9
17 3
1 18
8 10
16 19
1 6
7 2
5 12
1 18
8 20
5 18
8 5
4 16
1 15
5 19
18 19
17 10
1 10
17 3
10 2
3 10
17...

output:

-1 -1 -1 71 48 84 60 -1 69 -1 63 46 73 -1 71 -1 -1 -1 -1 72

result:

points 0.50 -1 correct

Test #9:

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

input:

100 400
87 45
42 17
9 81
65 10
8 82
76 48
39 73
21 58
76 30
76 92
74 76
99 90
38 50
86 74
75 52
8 2
80 55
20 95
66 60
78 82
10 18
22 59
23 17
63 76
56 51
38 10
50 65
41 28
64 77
59 53
100 66
38 84
23 47
17 9
45 75
41 28
33 41
8 78
2 95
3 11
40 15
60 63
23 17
82 2
61 44
44 16
77 34
100 66
96 99
68 12...

output:

-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1

result:

wrong answer wa

Subtask #3:

score: 0
Skipped

Dependency #1:

50%
Acceptable Answer

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

50%
Acceptable Answer

Dependency #2:

0%