Submission #637216

# Submission time Handle Problem Language Result Execution time Memory
637216 2022-08-31T23:36:49 Z MinaRagy06 KOVANICE (COI15_kovanice) C++17
0 / 100
2000 ms 64000 KB
#include <bits/stdc++.h>
using namespace std;
#define lesgooo ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl    '\n'
#define int     long long

const int N = 3e5+5;
vector<int> adj[N], comp[N];
int idx[N], vis[N], cur, indeg[N], val[N];
void dfs(int i)
{
    comp[cur].push_back(i), idx[i] = cur, vis[i] =  1;
    for (auto nxt : adj[i]) if (!vis[nxt]) dfs(nxt);
}
int depth(int i, int par)
{
    int ret = 1;
    for (auto nxt : adj[i]) if (nxt != par) ret = max(ret, 1+depth(nxt, i));
    return ret;
}
void assign(int i, int dep, int par)
{
    assert(!vis[i]);
    val[i] = dep, vis[i] = 1;
    for (auto nxt : adj[i]) if (nxt != par) assign(nxt, dep+1, i);
}
signed main()
{
    lesgooo;
    int n, m, v;
    cin >> n >> m >> v;
    pair<pair<int, char>, int> a[v];
    for (int i = 0; i < v; i++)
    {
        cin >> a[i].first.first >> a[i].first.second >> a[i].second;
        a[i].first.first--, a[i].second--;
        if (a[i].first.second == '=') adj[a[i].first.first].push_back(a[i].second), adj[a[i].second].push_back(a[i].first.first);
    }
    for (int i = 0; i < m; i++) if (!vis[i]) dfs(i), cur++;
    for (int i = 0; i < m; i++) adj[i].clear(), val[i] = -1;
    memset(vis, 0, sizeof vis);
    for (int i = 0; i < v; i++) if (a[i].first.second != '=') adj[idx[a[i].first.first]].push_back(idx[a[i].second]), indeg[idx[a[i].second]] = 1;
    for (int i = 0; i < cur; i++) if (!indeg[i] && !vis[i] && depth(i, 0) == n) assign(i, 1, 0);
    for (int i = 0; i < m; i++) cout << (val[idx[i]] == -1? "?" : "K"+to_string(val[idx[i]])) << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 26 ms 34104 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 88 ms 64000 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2082 ms 20396 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2076 ms 44036 KB Time limit exceeded
2 Halted 0 ms 0 KB -