Saratov State University :: Online Contester


::Go
- home
- news
- register
- update personal info
- problemset archive
- submit
- status online
- standing
- contests
- virtual contests
- forum
- statistic
- FAQ
- links
- projects

::Poll
Are you registered on Codeforces?
Yes
No
What is it???

[results]

::webboard

WA on test 10?
Author: Avril
ID: 045853
Problem: 226
Contest: 0
Date: 2011-08-22 22:07:46

Hi,

I have wrong answer on test 10 for this question
please help me :D
here is my code:

//In the name of Allah :D

#include<iostream>
#include<algorithm>
#include<vector>
#define pb push_back
#define s second
#define f first

using namespace std;

const int maxn=200+13;

vector<pair<int,int> > v[maxn];
bool mark1[maxn],mark2[maxn],mark3[maxn];
int meq1[maxn],meq2[maxn],meq3[maxn];
vector<int> saf;
int head,tail,ans;

void bfs(int u){
for(int i=0;i<(int)v[u].size();i++){
if(v[u][i].s==1 && (mark2[u] || mark3[u] || u==1)){
if(!mark1[v[u][i].f]){
mark1[v[u][i].f]++;
if(mark2[u] && mark3[u])
meq1[v[u][i].f]=min(meq2[u]+1,meq3[u]+1);
else
meq1[v[u][i].f]=max(meq2[u]+1,meq3[u]+1);
saf.pb(v[u][i].f);
tail++;
}
}
else if(v[u][i].s==2 && (mark3[u] || mark1[u] || u==1)){
if(!mark2[v[u][i].f]){
mark2[v[u][i].f]++;
if(mark1[u] && mark3[u])
meq2[v[u][i].f]=min(meq1[u]+1,meq3[u]+1);
else
meq2[v[u][i].f]=max(meq1[u]+1,meq3[u]+1);

saf.pb(v[u][i].f);
tail++;
}
}
else if(v[u][i].s==3 && (mark2[u] || mark1[u] || u==1)){
if(!mark3[v[u][i].f]){
mark3[v[u][i].f]++;
if(mark2[u] && mark1[u])
meq3[v[u][i].f]=min(meq2[u]+1,meq1[u]+1);
else
meq3[v[u][i].f]=max(meq2[u]+1,meq1[u]+1);

saf.pb(v[u][i].f);
tail++;
}
}
while(head<(int)saf.size())
bfs(saf[head++]);
}
}

int main(){
int n,m;
cin>>n>>m;
for(int i=0;i<m;i++){
int a,b,c;
cin>>a>>b>>c;
pair<int,int> tmp;
tmp.f=b;tmp.s=c;
v[a].pb(tmp);
}
bfs(1);
if(!mark1[n] && !mark2[n] && !mark3[n]){
cout<<-1<<endl;
return 0;
}
else if(mark1[n]){
ans=meq1[n];
if(mark2[n])
if(meq2[n]<ans)
ans=meq2[n];
if(mark3[n])
if(meq3[n]<ans)
ans=meq3[n];
}
else if(mark2[n]){
ans=meq2[n];
if(mark3[n])
ans=min(meq3[n],ans);
}
else
ans=meq3[n];
cout<<ans<<endl;
return 0;
}

see sub-tree reply to that message


::Login
Forgot password?

::News
22.10.12 - The problems from the Southern Subregional Programming Contest 2012 added to the problemset archive (542 - 553).
22.10.12 - After the start of the contest the statements in PDF will be available by the link.
23.10.11 - The problems from the Southern Subregional Programming Contest 2011 added to the problemset archive (530 - 541).

::Counter

Server time: 2017-09-21 12:41:04Online Contester Team © 2002 - 2016. All rights reserved.