### Saratov State University :: Online Contester

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

 ::Poll Are you registered on Codeforces?YesNoWhat 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
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;

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++;
}
}
}
}

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;
}