Submission #375250


Source Code Expand

#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

const int INF=1e9+7;

struct edge{
    int to,cost;
    edge(int a,int b):to(a),cost(b){}
    edge(){}
};

struct data{
    int pos,cost,prev;
    data(int a,int b,int c):pos(a),cost(b),prev(c){}
    data(){}
    bool operator<(const data &d)const{
        if(cost!=d.cost)return cost>d.cost;
        if(pos!=d.pos)return pos>d.pos;
        return prev>d.prev;
    }
};

int main(){
    int N,M;
    int x[100],y[100];
    vector<edge>G[100];

    scanf("%d%d",&N,&M);
    for(int i=0;i<N;i++)scanf("%d%d",&x[i],&y[i]);
    for(int i=0;i<M;i++){
        int a,b,c;scanf("%d%d%d",&a,&b,&c);
        a--;b--;
        G[a].push_back(edge(b,c));
        G[b].push_back(edge(a,c));
    }

    bool visited[100][100]={{0}};
    priority_queue<data>Q;

    Q.push(data(0,0,0));

    while(!Q.empty()){
        data d=Q.top();Q.pop();
        if(visited[d.pos][d.prev])continue;
        visited[d.pos][d.prev]=true;
        if(d.pos==1){
            printf("%d\n",d.cost);
            return 0;
        }

        for(int i=0;i<G[d.pos].size();i++){
            edge &e=G[d.pos][i];
            int x1=x[d.prev]-x[d.pos],x2=x[e.to]-x[d.pos];
            int y1=y[d.prev]-y[d.pos],y2=y[e.to]-y[d.pos];
            if(x1*x2+y1*y2<=0){
                Q.push(data(e.to,d.cost+e.cost,d.pos));
            }
        }
    }

    puts("-1");
    return 0;
}
/*
5 6
0 0
10 10
0 10
10 0
2 -6
1 2 30
1 3 4
1 4 5
1 5 1
2 4 3
2 5 1
*/

Submission Info

Submission Time
Task route - 象使い (Route)
User zerosun
Language C++ (G++ 4.6.4)
Score 100
Code Size 1586 Byte
Status AC
Exec Time 27 ms
Memory 928 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:31:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:32:50: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:34:43: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]

Judge Result

Set Name Set01 Set02 Set03 Set04 Set05 Set06 Set07 Set08 Set09 Set10
Score / Max Score 10 / 10 10 / 10 10 / 10 10 / 10 10 / 10 10 / 10 10 / 10 10 / 10 10 / 10 10 / 10
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
Set Name Test Cases
Set01 01
Set02 02
Set03 03
Set04 04
Set05 05
Set06 06
Set07 07
Set08 08
Set09 09
Set10 10
Case Name Status Exec Time Memory
01 AC 25 ms 804 KiB
02 AC 25 ms 804 KiB
03 AC 25 ms 804 KiB
04 AC 25 ms 928 KiB
05 AC 24 ms 804 KiB
06 AC 26 ms 928 KiB
07 AC 25 ms 812 KiB
08 AC 25 ms 928 KiB
09 AC 27 ms 924 KiB
10 AC 27 ms 800 KiB