QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#618685#9449. New School TermtovarischWA 0ms3552kbC++232.3kb2024-10-07 06:32:422024-10-07 06:32:43

Judging History

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

  • [2024-10-07 06:32:43]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3552kb
  • [2024-10-07 06:32:42]
  • 提交

answer

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


const int maxn = 10010;

int col[maxn];
int from[maxn], to[maxn];
vector<pair<int, int>> graph[maxn];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif // LOCAL

    int n, m; cin >> n >> m;
    for (int i=0; i<m; ++i) {
        cin >> from[i] >> to[i];
        from[i]--;
        to[i]--;

        graph[from[i]].push_back({to[i], i});
        graph[to[i]].push_back({from[i], i});
    }

    for (int i=0; i<2*n; ++i) col[i] = -1;

    vector<int> cnt = {0, 0};
    for (int i = m-1; i>=0; --i) {
        int u = from[i], v = to[i];

        if (col[u] != -1 && col[v] != -1) continue;

        if (cnt[0] >= n) {
            if (col[u] == -1) col[u] = 1, col[1]++;
            if (col[v] == -1) col[v] = 1, col[1]++;
        } else if (cnt[1] >= n) {
            if (col[u] == -1) col[u] = 0, col[0]++;
            if (col[v] == -1) col[v] = 0, col[0]++;
        } else {
            if(col[u] == -1 && col[v] == -1) {
                int c10 = -1, c01 = -1;

                for (auto& p : graph[u]) {
                    int w = p.first, k = p.second;

                    if (col[w] == 1) c10 = max(c10, k);
                    if (col[w] == 0) c01 = max(c01, k);
                }

                for (auto& p : graph[v]) {
                    int w = p.first, k = p.second;

                    if (col[w] == 1) c01 = max(c01, k);
                    if (col[w] == 0) c10 = max(c10, k);
                }

                if (c10 <= c01) col[u] = 1, col[v] = 0;
                else col[u] = 0, col[v] = 1;

                cnt[0]++;
                cnt[1]++;

            } else if (col[u] == -1) {
                if (cnt[1 - col[v]] < n) col[u] = 1 - col[v];
                else  col[u] = col[v];

                cnt[col[u]]++;
            } else if (col[v] == -1) {
                if (cnt[1 - col[u]] < n) col[v] = 1 - col[u];
                else col[v] = col[u];

                cnt[col[v]]++;
            }
        }
    }

    for (int i=0; i<2*n; ++i) {
        if (col[i] == -1)  col[i] = cnt[0]<n ? 0 : 1;

        cnt[col[i]]++;
        cout << col[i];
    }
    cout << endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 4
1 3
2 4
1 4
1 2

output:

1110

result:

wrong answer The number of 0s must be equal to that of 1s.