# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
846214 | vjudge1 | KOVANICE (COI15_kovanice) | C++98 | 60 ms | 76608 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long a,b,c,d;
cin>>a>>b>>c;
string kel;
long long arr[b + 5];
long long vis[b + 5];
vector <long long> es[b + 5];
queue <long long> que;
vector <long long> ana;
memset(arr,-1,sizeof(arr));
string str[c + 5];
vector <pair <long long,long long> > adj[b + 5];
d=0;
for(long long i=0;b>i;i++){
es[i].push_back(i);
}
for(long long i=0;c>i;i++){
cin>>kel;
if(kel[1] == '='){
adj[kel[2] - '1'].push_back(make_pair(kel[0] - '1',0));
adj[kel[0] - '1'].push_back(make_pair(kel[2] - '1',0));
}
else{
if(arr[kel[2] - '1'] == -1){
arr[kel[2] - '1'] = 0;
}
if(arr[kel[0] - '1'] == -1){
arr[kel[0] - '1'] = 0;
}
adj[kel[2] - '1'].push_back(make_pair(kel[0] - '1',1));
arr[kel[0] - '1']++;
}
}
for(long long i=0;b>i;i++){
if(arr[i] == 0){
ana.push_back(i);
}
}
memset(arr,-1,sizeof(arr));
memset(vis,0,sizeof(vis));
for(long long i=0;ana.size()>i;i++){
que.push(ana[i]);
arr[ana[i]] = 0;
}
long long pivot,enb;
enb=0;
while(que.size()){
cout<<pivot<<" ";
pivot = que.front();
que.pop();
if(vis[pivot] == 0){
vis[pivot] = 1;
for(long long i=0;adj[pivot].size()>i;i++){
if(vis[adj[pivot][i].first] == 0 ){
arr[adj[pivot][i].first] = arr[pivot] + adj[pivot][i].second;
if(enb < (arr[pivot] + adj[pivot][i].second)){
enb = arr[pivot] + adj[pivot][i].second;
}
que.push(adj[pivot][i].first);
}
}
}
}
if(a != (enb + 1)){
for(long long i=0;b>i;i++){
cout<<"?\n";
}
}
else{
for(long long i=0;b>i;i++){
if(arr[i] != -1){
cout<<"K"<<a - arr[i]<<"\n";
}
else{
cout<<"?\n";
}
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |