比赛 |
20161215 |
评测结果 |
AAAAAAAAAAAAAAA |
题目名称 |
相遇时间 |
最终得分 |
100 |
用户昵称 |
KZNS |
运行时间 |
0.015 s |
代码语言 |
C++ |
内存使用 |
0.31 MiB |
提交时间 |
2016-12-16 20:47:58 |
显示代码纯文本
//KZNS
#include <cstdio>
#include <utility>
#include <vector>
#include <queue>
using namespace std;
#define Nmax 103
typedef pair<int, int> poi;
class pr {
public:
int t, v;
bool operator () (const pr a, const pr b) {
return a.v > b.v;
}
};
int N, M;
class PE {
public:
vector<poi> gp[Nmax];
priority_queue<pr, vector<pr>, pr> ls;
void fir() {
ls.push((pr){1, 0});
}
int stt() {
int ans = -1;
pr pru;
int x, v;
while (!ls.empty()) {
pru = ls.top();
ls.pop();
x = pru.t;
v = pru.v;
if (x == N) {
ans = v;
break;
}
for (int i = 0; i < gp[x].size(); i++)
ls.push((pr){gp[x][i].first, v+gp[x][i].second});
}
return ans;
}
} AA, BB;
void init() {
scanf("%d %d", &N, &M);
int a, b, c, d;
for (int i = 0; i < M; i++) {
scanf("%d %d %d %d", &a, &b, &c, &d);
AA.gp[a].push_back(make_pair(b, c));
BB.gp[a].push_back(make_pair(b, d));
}
AA.fir();
BB.fir();
}
int main() {
freopen("meeting.in", "r", stdin);
freopen("meeting.out", "w", stdout);
init();
int a, b;
a = AA.stt();
b = BB.stt();
while (a != b) {
if (a < b) {
a = AA.stt();
if (a == -1)
b == -1;
}
else {
b = BB.stt();
if (b == -1)
a == -1;
}
}
if (a >= 0)
printf("%d\n", a);
else
printf("IMPOSSIBLE\n");
return 0;
}
//UBWH