Submission #637228

# Submission time Handle Problem Language Result Execution time Memory
637228 2022-09-01T00:45:49 Z MinaRagy06 KOVANICE (COI15_kovanice) C++17
100 / 100
347 ms 91300 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 = 5e5+5;
vector<int> adj[N], adj2[N], comp[N], path;
int idx[N], vis[N], cur, indeg[N], val[N], ans[N], dp[N], dp2[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)
{
    if (~dp[i]) return dp[i];
    dp[i] = 1, path.push_back(i);
    for (auto nxt : adj[i]) dp[i] = max(dp[i], 1+depth(nxt));
    return dp[i];
}
int assign(int i)
{
    if (~dp2[i]) return dp2[i];
    dp2[i] = 1;
    for (auto nxt : adj2[i]) dp2[i] = max(dp2[i], 1+assign(nxt));
    return dp2[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;
    for (int i = 0; i < v; i++) if (a[i].first.second != '=') adj[idx[a[i].first.first]].push_back(idx[a[i].second]), adj2[idx[a[i].second]].push_back(idx[a[i].first.first]), indeg[idx[a[i].second]] = 1;
    memset(dp, -1, sizeof dp), memset(dp2, -1, sizeof dp2);
    for (int i = 0; i < cur; i++) depth(i), assign(i);
    for (int i = 0; i < cur; i++) if (dp2[i] + dp[i]-1 < n) dp2[i] = -1;
    for (int i = 0; i < m; i++) ans[i] = dp2[idx[i]];
    for (int i = 0; i < m; i++) cout << (ans[i] == -1 || ans[i] == 1e18? "?" : "K"+to_string(ans[i])) << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 22 ms 43476 KB Output is correct
2 Correct 21 ms 43540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 64696 KB Output is correct
2 Correct 124 ms 64776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 48076 KB Output is correct
2 Correct 39 ms 48356 KB Output is correct
3 Correct 40 ms 48224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 292 ms 82580 KB Output is correct
2 Correct 329 ms 85804 KB Output is correct
3 Correct 294 ms 85688 KB Output is correct
4 Correct 335 ms 90500 KB Output is correct
5 Correct 347 ms 91300 KB Output is correct