답안 #1036086

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1036086 2024-07-27T03:30:10 Z HNa_seawjing Robot (JOI21_ho_t4) C++14
0 / 100
58 ms 25644 KB
#include <bits/stdc++.h>
//code
#define fl(i,x,y,z) for(int i=x;i<=y;i=i+z)
#define fn(i,x,y,z) for(int i=x;i>=y;i=i-z)
#define rep(i,x,y) for(int i=x;i<y;i=i+1)
#define all(v) v.begin(),v.end()
#define pb push_back
#define tle cout<<"tle"<<endl
#define edl cout<<"\n"
#define el "\n"
#define getbit(x,i) ((x>>i)&1)
#define bitcnt __builtin_popcount
//ham
#define pii pair<long long,long long>
#define fi first
#define se second
#define ll long long
#define ld long double
#define inf 0x3f3f3f3f
//#define int long long
#define mp make_pair
using namespace std;
const ll mod=1e9+7;
int n,m;
struct kb
{
    int v,c,p;
};
vector <pair<int,pii>> e[100005];
vector <pii> a[100005];
int vis[1000005],t[1000005];
ll d[1000005];
priority_queue <pii,vector <pii>, greater <pii>> q;
//void inp()
//{
//    cin>>n>>m;
//    fl(i,1,m,1)
//    {
//        int u,v,c,p;
//        cin>>u>>v>>c>>p;
//        e[u].pb({v,{c,p}});
//        e[v].pb({u,{c,p}});
//        a[u].pb({v,p});
//        a[v].pb({u,p});
//
//    }
//}
void dij()
{
    fl(i,1,n,1) d[i]=1e18;
    d[1]=0;
    q.push({d[1],1});
    while (!q.empty())
    {
        int u=q.top().se;
        int c=q.top().fi;
        q.pop();
        if (vis[u]) continue;
        vis[u]=1;
        for (auto it: a[u])
        {
            int v=it.fi,w=it.se;
            if (vis[v]==false && d[v]>d[u]+w)
            {
                d[v]=d[u]+w;
                q.push({d[v],v});
            }
        }
    }
}
//void sol()
//{
//    int cur = n;
//	fl(i,1,n,1)
//	{
//		sort(e[i].begin(), e[i].end());
//		for (auto it : e[i])
//			t[it.fi] += it.se.se;
//		for (auto it : e[i])
//		{
//			if (!vis[it.fi])
//			{
//				++cur;
//				a[i].push_back({cur,0});
//			}
//			vis[it.fi]=1;
//			a[cur].push_back({it.se.fi, t[it.fi]-it.se.se});
//			a[it.se.fi].push_back({cur, 0});
//		}
//		for (auto it : e[i])
//		{
//			t[it.fi] = 0;
//			vis[it.fi] = 0;
//		}
//	}
//    dij();
//}
void dij(int x)
{
	fl(i,1,n,1) d[i] = 1e9;
	priority_queue< pair < int,int > , vector < pair < int ,int > > , greater < pair < int , int > > > q;
	d[x] = 0;
	q.push(mp(0, x));
	while (!q.empty())
	{
		auto p1 = q.top();
		int W = p1.fi;
		int x = p1.se;
		q.pop();
		if (vis[x])
			continue;
		vis[x] = 1;
		for (auto p2 : a[x])
		{
			int y = p2.fi;
			int w = p2.se;
			if (vis[y] || d[y] < W + w)
				continue;
			d[y] = W + w;
			q.push({W + w, y});
		}
	}
}
void sol()
{
	cin >> n >> m;
	fl(i,1,m,1)
	{
	    int x,y,c,p;
		cin >> x >> y >> c >> p;
		e[x].push_back({c, {y, p}});
		e[y].push_back({c, {x, p}});
		a[x].push_back({y, p});
		a[y].push_back({x, p});
	}
	int cur = n;
	fl(i,1,n,1)
	{
		sort(e[i].begin(), e[i].end());
		for (auto it : e[i])
			t[it.fi] += it.se.se;
		for (auto it : e[i])
		{
			if (!vis[it.fi])
			{
				++cur;
				a[i].push_back(mp(cur,0));
			}
			vis[it.fi] = 1;
			a[cur].push_back(mp(it.se.fi, t[it.fi] - it.se.se));
			a[it.se.fi].push_back(mp(cur, 0));
		}
		for (auto it : e[i])
		{
			t[it.fi] = 0;
			vis[it.fi] = 0;
		}
	}
	dij();
	if (d[n] == 1e0)
		cout << "-1";
	else
		cout << d[n];
//	return 0;
}
signed main()
{
//    freopen("task.inp","r",stdin);
//    freopen("task.out","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    inp();
    sol();
    return 0;
}
/*   /\_/\
    ( ._. )
    / >V< \
*/

Compilation message

Main.cpp: In function 'void dij()':
Main.cpp:56:13: warning: unused variable 'c' [-Wunused-variable]
   56 |         int c=q.top().fi;
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4952 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 58 ms 25644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 4952 KB Output isn't correct
2 Halted 0 ms 0 KB -