#include <bits/stdc++.h>
#define N 300005
using namespace std;
int par[N];
int find(int a){
if(a == par[a])return a;
return par[a] = find(par[a]);
}
bool merge(int a,int b){
a = find(a);
b = find(b);
if(a == b)return 0;
par[a] = b;
return 1;
}
vector<int> adj[N];
int a[N],b[N];
char c[N];
bool ok[N];
bool vis[N];
int ans[N];
vector<int> ord;
void dfs(int v){
vis[v] = 1;
for(auto u:adj[v]){
if(vis[u])continue;
dfs(u);
}
ord.push_back(v);
}
void solve(){
int n,m,v;
cin >> n >> m >> v;
for(int i = 1;i<=m;i++){
par[i] = i;
ok[i] = 1;
ans[i] = -1;
}
for(int i = 1;i<=v;i++){
cin >> a[i] >> c[i] >> b[i];
if(c[i] == '=')
merge(a[i],b[i]);
}
for(int i = 1;i<=v;i++){
a[i] = find(a[i]);
b[i] = find(b[i]);
if(c[i] == '<'){
ok[a[i]] = 0;
adj[b[i]].push_back(a[i]);
}
}
for(int i = 1;i<=m;i++){
if(ok[i] && i == find(i)){
ord.clear();
dfs(i);
for(int j = 0;j<ord.size();j++){
vis[ord[j]] = 0;
if(ord.size() == n){
ans[ord[j]] = j+1;
}
}
}
}
for(int i = 1;i<=m;i++){
if(ans[find(i)] == -1){
cout << "?" << endl;
}
else cout << "K" << ans[find(i)] << endl;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while(t--){
solve();
}
#ifdef Local
cout << endl << fixed << setprecision(2) << 1000.0*clock()/CLOCKS_PER_SEC << " milliseconds.";
#endif
}
Compilation message
kovanice.cpp: In function 'void solve()':
kovanice.cpp:56:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int j = 0;j<ord.size();j++){
| ~^~~~~~~~~~~
kovanice.cpp:58:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
58 | if(ord.size() == n){
| ~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
7380 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
269 ms |
11992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
8916 KB |
Output is correct |
2 |
Correct |
21 ms |
8916 KB |
Output is correct |
3 |
Correct |
22 ms |
8816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2072 ms |
17520 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |