当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

4889:Scary Path Finding Algorithm

Special Judge 特殊评判
题目描述
Fackyyj loves the challenge phase in TwosigmaCrap(TC). One day, he meet a task asking him to find shortest path from vertex 1 to vertex n, in a graph with at most n vertices and m edges. (1 ≤ n ≤ 100,0 ≤ m ≤ n(n-1))

Fackyyj solved this problem at first glance, after that he opened someone's submission, spotted the following code:

long long spfa_slf() {
int n,m;
cin >> n >> m;

vector<pair<int,int> > edges[111];
for(int i = 0;i < m;i++) {
int x,y,w;
cin >> x >> y >> w;
edges[x].push_back(make_pair(y,w));
}

deque<int> q;
vector<long long> dist(n+1, ~0ULL>>1);
vector<bool> inQueue(n+1, false);
dist[1] = 0; q.push_back(1); inQueue[1] = true;

int doge = 0;
while(!q.empty()) {
int x = q.front(); q.pop_front();
if(doge++ > C) {
puts("doge");
return 233;
}
for(vector<pair<int,int> >::iterator it = edges[x].begin();
it != edges[x].end();++it) {
int y = it->first;
int w = it->second;
if(dist[y] > dist[x] + w) {
dist[y] = dist[x] + w;
if(!inQueue[y]) {
inQueue[y] = true;
if(!q.empty() && dist[y] > dist[q.front()])
q.push_back(y);
else
q.push_front(y);
}
}
}
inQueue[x] = false;
}
return dist[n];
}

Fackyyj's face lit up with an evil smile. He immediately clicked button "Challenge!", but due to a hard disk failure, all of his test case generators were lost! Fackyyj had no interest on recreating his precise generators, so he asked you to write one. The generator should be able to generate a test case with at most 100 vertices, and it must be able to fail the above code, i.e. let the above code print "doge". It should NOT contain any negative-cost loop.

 For those guys who doesn't know C++, Fackyyj explain the general idea of the above algorithm by the following psuedo-code:

输入解释
Input contains several test cases, please process till EOF.
For each test case, there will be a single line containing an integer C. It is the constant C in the above code. (C <= 23333333)
输出解释
For each test case, on the first line, print two integers, n and m, indicating the number of vertices and the number of edges of your graph. Next m lines, on each line print x y w, means there is a road from x to y, cost w.
1 ≤ n ≤ 100,0 ≤ m ≤ n(n-1),|w| < 231. Note that your output shouldn't contain any negative-cost loop.
输入样例
1
输出样例
4 3
1 2 1
2 3 1
3 4 1
来自杭电HDUOJ的附加信息
Author Fudan University
Recommend

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-4889

最后修改于 2020-10-25T23:17:48+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 65536/65536K(Java/Others)