Access violation N 3
Послано
Lord_F 11 фев 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 read(a) scanf("%ld",&a);
#define readf(a) scanf("%lf",&a);
#define read2(a,b) scanf("%ld %ld",&a,&b)
#define read2f(a,b) scanf("%lf %lf",&a,&b)
#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;
read(n); scanf("\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??