Submission #81716

# Submission time Handle Problem Language Result Execution time Memory
81716 2018-10-26T10:02:21 Z Saboon Teoretičar (COCI18_teoreticar) C++14
0 / 130
12000 ms 263168 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 maxm = 3e6 + 37;
const int maxn = 5e3 + 100;
int col[maxm], 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 d[maxn], dp[maxn];

int main() {
    ios_base::sync_with_stdio(false);
    int n, m, e;
    cin >> n >> m >> e;
    int Maxd = 0;
    for (int i = 1; i <= e; i++) {
        int v, u;
        cin >> v >> u;
        g[v].PB ({u, i});
        d[v] ++;
        dp[v] ++;
        Maxd = max (Maxd, d[v]);
        Maxd = max (Maxd, dp[v]);
    }
    n = max (n, m);
    m = max (n, m);
    int tmp = e + 1;
    for (int i = 1; i <= n; i++) {
        if (d[i] < Maxd) {
            for (int j = 1; d[i] < Maxd and j <= m; j++) {
                while (d[i] < Maxd and dp[j] < Maxd) {
                    g[i].PB ({j, tmp ++});
                    d[i] ++;
                    dp[j] ++;
                }
            }
        }
    }

    int c = 1, cop = tmp - 1;
    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';
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 504 KB too many colors
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 688 KB too many colors
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 968 KB too many colors
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1668 ms 8992 KB Output is correct
2 Incorrect 63 ms 8992 KB too many colors
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 8992 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 8992 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 816 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 12082 ms 263168 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 12084 ms 263168 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 504 ms 263168 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -