/*
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] = 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
18720 KB |
Output is correct |
2 |
Correct |
10 ms |
18720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
158 ms |
22152 KB |
Output is correct |
2 |
Correct |
176 ms |
22020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2000 ms |
19380 KB |
Execution timed out |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2000 ms |
27828 KB |
Execution timed out |
2 |
Halted |
0 ms |
0 KB |
- |