제출 #39914

#제출 시각아이디문제언어결과실행 시간메모리
399145ak0KOVANICE (COI15_kovanice)C++14
50 / 100
2000 ms27828 KiB
/* ID: 5ak0 PROG: LANG: C++11 */ #include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define mpr make_pair using namespace std; typedef long long ll; typedef pair<int, int> pii; const int INF = 1e9 + 7, MAXN = 3e5 + 10; bool u[MAXN]; int mp[MAXN]; vector <int> g[MAXN], g1[MAXN]; int a, b, cnt[MAXN]; char ch; int n, m, v; void dfs(int v){ u[v] = 1; for (auto to : g[v]){ if (u[to] == 0){ mp[to] = mp[v]; dfs(to); } } } void dfs1(int v){ for (auto to : g1[v]){ mp[to] = max(mp[to], mp[v] + 1); dfs1(to); } } int main(){ cin >> n >> m >> v; for (int i = 1; i <= v; ++i){ cin >> a >> ch >> b; if (ch == '<'){ g1[a].pb(b); ++cnt[b]; } else{ g[a].pb(b); g[b].pb(a); } } for (int i = 1; i <= m; ++i){ if (cnt[i] == 0 && g1[i].size() != 0){ mp[i] = 1; dfs1(i); } } for (int i = 1; i <= m; ++i) if (u[i] == 0 && mp[i] != 0) dfs(i); for (int i = 1; i <= m; ++i){ if (mp[i] == 0) cout << "?\n"; else{ cout << "K" << mp[i] << "\n"; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...