답안 #81702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
81702 2018-10-26T09:04:52 Z Saboon Teoretičar (COCI18_teoreticar) C++14
26 / 130
362 ms 17940 KB
#include <iostream>
#include <sstream>
#include <queue>
#include <stack>
#include <vector>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <iomanip>
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn = 1e5 + 37;

int col[maxn], edge[maxn], match[maxn];
vector <pii> g[maxn];
bool visited[maxn];

bool dfs (int v) {
    if (visited[v])
        return false;
    visited[v] = 1;
    for (auto u : g[v]) {
        if (col[u.S] != 0)
            continue;
        if (match[u.F] == -1 or dfs (match[u.F])) {
            match[u.F] = v;
            edge[u.F] = u.S;
            return true;
        }
    }
    return false;
}

int main() {
    ios_base::sync_with_stdio(false);
    int n, m, e;
    cin >> n >> m >> e;
    for (int i = 1; i <= e; i++) {
        int v, u;
        cin >> v >> u;
        g[v].PB ({u, i});
    }
    for (int i = 1; i <= n; i++)
        random_shuffle (g[i].begin(), g[i].end());
    int c = 1, cop = e;
    while (cop) {
        memset (match, -1, sizeof match);
        int tmp = 0;
        for (int i = 1; i <= n; i++) {
            memset (visited, 0, sizeof visited);
            tmp += dfs (i);
        }
        cop -= tmp;
        for (int i = 1; i <= m; i++)
            if (match[i] != -1)
                col[edge[i]] = c;
        c ++;
    }
    cout << c - 1 << endl;
    for (int i = 1; i <= e; i++)
        cout << col[i] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3192 KB Output is correct
2 Correct 7 ms 3192 KB Output is correct
3 Correct 9 ms 3224 KB Output is correct
4 Correct 5 ms 3224 KB Output is correct
5 Correct 5 ms 3412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 3412 KB Output is correct
2 Correct 18 ms 3472 KB Output is correct
3 Correct 8 ms 3472 KB Output is correct
4 Correct 5 ms 3472 KB Output is correct
5 Correct 5 ms 3520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 90 ms 3524 KB too many colors
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 3652 KB Output is correct
2 Correct 87 ms 3652 KB Output is correct
3 Correct 362 ms 3652 KB Output is correct
4 Incorrect 36 ms 3652 KB too many colors
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 158 ms 16444 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 161 ms 16444 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 129 ms 16444 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 151 ms 17940 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 123 ms 17940 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 107 ms 17940 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -