ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1837. Isenbaev's Number

Access violation N 3
Posted by Lord_F 11 Feb 2013 21:41
#include <cstdio>
#include <deque>
#include <queue>
#include <vector>
#include <string>
#include <set>
#include <stack>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <fstream>
#include <climits>
#include <cfloat>
#include <map>
#include <cstring>

#define FOR(i,s,e) for(long i = s; i < e; ++i)
#define FORD(i,e,s) for(long i =e-1; i>=s; --i)
#define write(a) printf("%ld ",a);
#define writef(a) printf("%lf ",a);
#define write2(a,b) printf("%ld %ld ",a,b)
#define write2f(a,b) printf("%lf %lf ",a,b)
#define writeln(a) printf("%ld\n",a);
#define writelnf(a) printf("%lf\n",a);
#define writeln2(a,b) printf("%ld %ld\n",a,b)
#define writeln2f(a,b) printf("%lf %lf\n",a,b)
#define nln printf("\n")
#define elif else if
#define MOD 1000007
#define EPS 1e-9
#define INF 2117117117
#define mp(a,b) make_pair(a,b)
#define dist(x1,y1,x2,y2) sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))
#define pb(a) push_back(a)

using namespace std;

int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
long n;
map<string, long> m;
vector<long> g[318];
long c=0;
string s1,s2,s3;
FOR(i,0,n)
{
getline(cin,s1,' ');
if (m.find(s1)==m.end())
m.insert(mp(s1,c++));
getline(cin,s2,' ');
if (m.find(s2)==m.end())
m.insert(mp(s2,c++));
getline(cin,s3,'\n');
if (m.find(s3)==m.end())
m.insert(mp(s3,c++));
long a=m.find(s1)->second,b=m.find(s2)->second,c=m.find(s3)->second;
g[a].pb(b); g[a].pb(c); g[b].pb(a); g[b].pb(c); g[c].pb(a); g[c].pb(b);
}
long d[318];
FOR(i,0,c)
d[i]=-1;
long s = m.find("Isenbaev")->second;
d[s]=0;
queue<long> q;
q.push(s);
long v;
while (!q.empty())
{
v=q.front();
q.pop();
FOR(i,0,g[v].size())
{
if (d[g[v][i]]==-1)
{
d[g[v][i]]=d[v]+1;
q.push(g[v][i]);
}
}
}
map<string, long>::iterator it;
for( it = m.begin(); it != m.end(); ++it)
{
printf("%s ",it->first.c_str());
if (d[it->second]==-1)
printf("undefined");
else
write(d[it->second]);
nln;
}
return 0;
}

Why??
Re: Access violation N 3
Posted by Lord_F 11 Feb 2013 21:45
Oh, I see now, there is no Isenbaev in the 3rd test, so all people are undefined.